随笔 - 61  文章 - 48  trackbacks - 0
<2007年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

留言簿(10)

随笔档案

收藏网站

搜索

  •  

最新评论

阅读排行榜

评论排行榜

Xml文件格式需要UTF8,而Php默认配置下,用fopen新建的文件都是ASCII格式的,如何让fopen生成新文件时使用UTF8格式呢?
      其实没有特殊技巧,把你要执行的脚本改成utf8格式,fopen生成的新文件在内容包含ASCII字符以外的字符时格式就是utf8格式,内容仅包含ASCII字符仍然是ASCII格式的。

示例:000-297.Php

000-297.Php必须为utf8格式

<?Php
$filename = 'test.txt';
//$somecontent = "test\n";
$somecontent = "test中文\n";
if (!$handle = fopen($filename, 'w+')) {
  echo "Cannot open file ($filename)";
  exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
 echo "Cannot write to file ($filename)";
 exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
?>

 

posted on 2007-09-06 09:48 php一道 阅读(1230) 评论(0)  编辑 收藏 引用 网摘

只有注册用户登录后才能发表评论。
网站导航: