==>简体_PHP
- WBOY原创
- 2016-06-01 12:35:541075浏览
/**** 繁体简体 ****/
/**
码表的取得:
http://netcity.hinet.net/kstchieh/table.zip
包中有两个文件:big5-gb.table,gb-big5.table
函数gb2big5由于没有big5环境,故未能详细测试
*/
// 将码表予装入内存
$filename = "big5-gb.table";
$fp = fopen($filename, "rb");
$big5 = fread($fp,filesize($filename));
fclose($fp);
$filename = "gb-big5.table";
$fp = fopen($filename, "rb");
$gb = fread($fp,filesize($filename));
fclose($fp);
/**
Big5码转换成GB码
*/
function big52gb($Text) {
global $big5;
$max = strlen($Text)-1;
for($i=0;$i
$h = ord($Text[$i]);
if($h>=160) {
$l = ord($Text[$i+1]);
if($h==161 && $l==64) {
$gb = " ";
}else{
$p = ($h-160)*510+($l-1)*2;
$gb = $big5[$p].$big5[$p+1];
}
$Text[$i] = $gb[0];
$Text[$i+1] = $gb[1];
$i++;
}
}
return $Text;
}
/**
GB码转换成Big5码
*/
function gb2big5($Text) {
global $gb;
$max = strlen($Text)-1;
for($i=0;$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;
}
?>
/**** 测试 ****/
$a = "啊阿埃挨哎唉哀皑癌蔼矮艾碍爱隘鞍氨";
echo "原简体 $a
";
$a = "摆甁玼玸絁砾魔窯︺锚稲筰綽";
echo "原繁体 $a
";
$a=big52gb($a);
echo "转简体 $a
";
$a=gb2big5($a);
echo "转繁体 $a
";
?>
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn