Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

What character encoding does fwrite use?

What character encoding does fwrite use by default and how can this be controlled?
<?php
   $data = "Hello. Buenos días. Ça Va. Yá'át'ééh.";
   $fp = fopen($file, 'w');
   fwrite($fp, $data);
   fclose($fp);
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of alain34
alain34
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hankknight

ASKER

alain34, your idea is to do this:

fwrite($fh,utf8_encode($myString));

The problem is that the string is ALREADY in UTF-8 encoding.  

And to double encode this could cause some problems!
https://www.experts-exchange.com/questions/24146810/using-utf8-encode-on-text-that-is-already-encoded.html

So I can't leave it as it is because of the UTF-8 fwrite bug you noted.  And I can't convert it because it would get scrambled!  Either way the text gets damaged!