php实现简->繁转换的问题,查了N多资料,百思不得其解,在线求教
先谢谢各位了.
这是代码:
<?php
$filename="73hduip3_d3s/h73ghdn_3hx78.icbuy"; //gb2312->big5的码表....
$fp=fopen($filename,"rb");
$gb=fread($fp,filesize($filename));
fclose($fp);
function gb2big5($text) {
global $gb;
$max=strlen($text)-1;
for ($i=0;$i<$max;$i++) {
$h=ord($text[$i]);
if ($h>=160) {
$l=ord($text[$i+1]);
if ($h==161 && $l==64) {
$big=" ";
}
else {
$p=($h-160)*510+($l-1)*2;
$big=$gb[$p].$gb[$p+1];
}
$text[$i]=$big[0];
$text[$i+1]=$big[1];
$i++;
}
}
return $text;
}
if ($_GET["url"]=="/") $_GET["url"]="/index.php";
$from_chk_1=strpos($_GET["url"],'http://');
$from_chk_2=strpos($_GET["url"],'ftp://');
$from_chk_3=strpos($_GET["url"],'www.');
if ($from_chk_1==true || $from_chk_2==true || $from_chk_3==true) die('where will you go?');
$file_name="http://www.xxxxxx.net".$_GET["url"];
$file_content=fopen($file_name,"r");
if (!$file_content) {
echo "无法读取源文件.<b>sorry, i can't read the resource.";
exit;
}
/*while (!feof($file_content)) {
$content=fgets($file_content,2000);
}*/
$content=fread($file_content);
fclose($file_content);
$content=str_replace("charset=gb2312","charset=big5",$content);
echo gb2big5($content);
?>
这样的话报错 Warning: Wrong parameter count for fread() in /data/www/xxxx/transfer/index.php on line 49
如果去掉上面的 $content=fread($file_content); ,恢复被注释的内容, 无任何报错, 页面无任何输出, 查看源文件失效.
各位能否帮我看看, 问题在哪里. 若有更好建议, 我感激不尽.