首页 > 其他 > 详细

fwrite() and UTF8 转载

时间:2014-02-21 07:48:57      阅读:354      评论:0      收藏:0      [点我收藏+]

If you know the data is in UTF8 than you want to set up the header.

I wrote a solution answering to another tread.

The solution is the following: As the UTF-8 byte-order mark is \xef\xbb\xbf we should add it to the document‘s header.

<?php
function writeStringToFile($file, $string){
    $f=fopen($file,"wb");
    $file="\xEF\xBB\xBF".$file;// this is what makes the magic
    fputs($f, $string);
    fclose($f);}?>

You can adapt it to your code, basically you just want to make sure that you write a UTF8 file (as you said you know your content is UTF8 encoded).

share|improve this answer
 
   
UTF8 BOM meaning 0xEF,0xBB,0xBF, which is precisely what I suggested. Now you obviously can create a file as UTF-8 by changing settings in your IDE. But the same thing can be achieved using just PHP.–  Florin SimaSep 10 ‘12 at 15:30
   
+1 This should be the correct answer–  ErgecAug 14 ‘13 at 18:38

fwrite() and UTF8 转载

原文:http://www.cnblogs.com/xcwytu/p/3558246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!