note 73764 modified in function.fwrite by bobby
| From: | bobby@php.net | Date: | Sun, 25 Mar 2007 05:24:28 +0000 |
| Subject: | note 73764 modified in function.fwrite by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124780@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 = "Test with accents éèà ç";
$fh=fopen('test.xml',"w");
fwrite($fh,utf8_encode($myString));
fclose($fh);
?>
Hope this will help
--was--
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
http://php.net/manual/en/function.fwrite.php