php簡體轉換繁體
2015.09.10 | 910閱讀 | 0條評論 | php
最近做一個網站,需要顯示的是簡體和繁體字,所以網上看了些教材。做了下記錄。
先通過對照表gb-big5.table,將輸入轉為gib5碼,然后再通過iconv函數(shù)轉成utf-8碼,當然也可以轉成其它。
[caption id="attachment_1311" align="alignleft" width="78" caption="gb-big5.table"][/caption]
[php]
echo iconv("utf-8","gbk",gb2big5("中國福建省龍巖市新羅區(qū)"));
function gb2big5($Text) {
$filename = "gb-big5.table";
$fp = fopen($filename, "rb");
$gb = fread($fp,filesize($filename));
$Text = iconv("utf-8","gb2312",$Text);
$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 iconv("big5","utf-8",$Text);
}
[/php]
發(fā)表評論