note 73764 added to function.fwrite
| From: | cutmaster at fearlesss dot com | Date: | Fri, 09 Mar 2007 11:09:59 +0000 |
| Subject: | note 73764 added to function.fwrite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124263@lists.php.net to get a copy of this message | ||
For those who, like me, lost a lot of minutes (hours) to understand why fwrite doesn't create a
real utf-8 file, here's the explanation I've found :
I tried to do something like this :
<?php
$myString = utf8_encode("Test with accents éèà ç");
$fh=fopen('test.xml',"w");
fwrite($fh,$myString);
fclose($fh);
?>
For a mysterious reason, the resulted file shows the accent without the utf-8 conversion.
I tried the binary, mode, etc. etc. And finally I've found it :
It seems that fwrite NEEDS to have the utf8_encode function INSIDE its parameters like this, to
understand it must create a non-text only file :
<?php
$myString = utf8_encode("Test with accents éèà ç");
$fh=fopen('test.xml',"w");
fwrite($fh,utf8_encode($myString));
fclose($fh);
?>
Hope this will help
----
Server IP: 217.174.196.197
Probable Submitter: 83.142.151.166
----
Manual Page -- http://www.php.net/manual/en/function.fwrite.php
Edit -- https://master.php.net/note/edit/73764
Del: integrated -- https://master.php.net/note/delete/73764/integrated
Del: useless -- https://master.php.net/note/delete/73764/useless
Del: bad code -- https://master.php.net/note/delete/73764/bad+code
Del: spam -- https://master.php.net/note/delete/73764/spam
Del: non-english -- https://master.php.net/note/delete/73764/non-english
Del: in docs -- https://master.php.net/note/delete/73764/in+docs
Del: other reasons-- https://master.php.net/note/delete/73764
Reject -- https://master.php.net/note/reject/73764
Search -- https://master.php.net/manage/user-notes.php