Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:39:38+00:00 2026-06-15T09:39:38+00:00

SOLUTION: $output = ‘–– € ––’; //written like this php 5 does not understand

  • 0

SOLUTION:

    $output = '–– € ––'; 
//written like this php 5 does not understand because it interprets it as single-byte chars.
//so i found the function below to write a multi-byte char in a string.

//unicode version of php's chr()
function uchr ($codes) {
    if (is_scalar($codes)) $codes= func_get_args();
    $str= '';
    foreach ($codes as $code) $str.= html_entity_decode('&#'.$code.';',ENT_NOQUOTES,'UTF-8');
    return $str;
}

//decimal values of unicode chars: – 8211 - 8211, [space] 32, € 8364,[space] 32, – 8211 - 8211
$output = uchr(8211,8211,32,8364,32,8211,8211);

//or
$output = uchr(8211,8211).' '.uchr(8364).' '.uchr(8211,8211);

echo $output;

QUESTION:

How can i write these special chars to a simple file?

$file = "./upload/myfile.txt";
$output = "–– € ––".PHP_EOL; // the "–" is not an underscore _ or - but –
file_put_contents($file, $output);

If I access this file from the browser http://mydomain.com/upload/myfile.txt i only get “�” characters.

However if i save “–– € ––” with Zend Developer or my local texteditor (on OSX) and upload this everything is perfectly fine. The browser shows it correctly.

How can i achieve this with php? it seems php uses a different way of writing the file than my macbook. thought i thought php’s standard was UTF-8 and i also saved the file as UTF-8 in my local text editor.

EXTRA INFO: in the .htaccess file that’s in the upload folder i wrote:

  AddDefaultCharset utf-8
  AddCharset utf-8 .txt

otherwise the firebug addon from firefox gave a message that the charset was not specified.

any ideas?
It has to do with saving the file because my uploaded file shows correctly.

i tried different options while saving the file like:

$output = mb_convert_encoding($output, 'UTF-8', 'OLD-ENCODING');

and the iconv function of php, but i cant find the solution.

any help is greatly appreciated.

EDIT: if i get the content from my uploaded file and echo it the following happens

$output = file_get_contents('./upload/myuploadedfile.txt',FILE_USE_INCLUDE_PATH); 
//it show correctly –– € ––
$output = $output[1]; //it shows a �
$output = $output[3]; //it shows a �

echo $output;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:39:39+00:00Added an answer on June 15, 2026 at 9:39 am

    PHP will write the contents of the file exactly as they are in your source code. It takes bytes exactly as they are encoded in your .php file and puts them in a file. From then it depends on how the file is interpreted. Assuming your source code is actually UTF-8 encoded, so will the file be. Try opening it with a text editor that can understand UTF-8. Change the encoding the browser interprets it with to UTF-8 (View menu > Encoding). Check if the web server actually sets the correct charset header when you open it in the browser (Firebug Network tab, headers of the response).

    It’s correct that $output[0] shows a broken UTF-8 character, since PHP only gives you the first byte of the multi-byte character “–”.

    For more in-depth information, see What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This below output come from php json_encode.What we see here is 0849 is twice.Since
I am using this solution found on stackoverflow to encode my MYSQL output to
I tried this solution: iptables -I OUTPUT -p tcp --dport 2195 -j ACCEPT /etc/init.d/iptables
I have a solution which has multiple output projects (a website, and admin tool,
solution:[a-zA-Z0-9.!#$%&'*+-/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)* is a good choice I am using a regular expression like the below
Solution at end of this post. By default the time is set to one
I have a Visual Studio 2008 Solution where the main output exe is a
Usually, visual studio puts output files to bin/debug or bin/release. When solution contains a
I have a solution with 40 projects in it. I've recently reconfigured output path
I have a simple WinForms solution in VS 2010. Whenever I build it, output

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.