<?
$file_hdl = fopen("big5.map","r");
//$str = fgets($file_hdl);
//echo $str;
function cgb_big5($str,$fd)
{
$length = strlen($str);
$final = "";
for ($i=0;$i<$length;$i++)
{
$temp = substr($str,$i,1);
if (ord($temp)>127)//127这个数字是汉字第一部分的ascii码,可能不准
{
$temp = substr($str,$i,2);
$first = ord(substr($temp,0,1));
$last = ord(substr($temp,1,1));
//echo $c."<BR>".$x."<BR>";
$address = (($first-160)*510)+($last-1)*2;
//echo $address."<BR>";
fseek($fd, $address);
$head = fgetc($fd);
$tail = fgetc($fd);
$final .= $head.$tail;
$i++;
}
else
{
$final .= $temp;
}
}
return "$final";
}
//echo cgb_big5("A.123这就是爱情;绝对绝对",$file_hdl);
$test_str ='A.aaa.sdfsdf.123123.我爱你啊';
echo cgb_big5($test_str,$file_hdl);
?>
http://203.68.102.46/online_book/data/12/24/big5.map
这是big5.map的下载地址
程序会自动把简体汉字转换为繁体,其他字符不变,希望大家提出宝贵的意见 |