下面代码就是读取.txt中内容并转为UTF-8格式
<?php
<?php
$filename = "filename.txt";
$handle = fopen($filename, "r");//读取二进制文件时,需要将第二个参数设置成'rb'
//通过filesize获得文件大小,将整个文件一下子读到一个字符串中
$contents = fread($handle, filesize ($filename));
$e=mb_detect_encoding($contents, array('UTF-8', 'CP936'));
switch($e){
case 'UTF-8':
break;
case 'CP936':$contents=iconv("GB2312", "UTF-8", $contents);
break;
}
fclose($handle);
?>