ホームページ  >  記事  >  バックエンド開発  >  繁体字中国語を簡体字中国語に変換する PHP 関数_PHP チュートリアル

繁体字中国語を簡体字中国語に変換する PHP 関数_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 16:02:181153ブラウズ

数日前、私は oso フォーラムでそのようなソースプログラムがあるかどうか尋ねましたが、誰も答えませんでした。移植用の Delphi ソース コードを提供してくれた netizen Keyes に感謝します。呼び出しメソッドは $txt=big5togb($txt) です。
(注: ソース コードに「data_big5.php」を含めてください。このファイルは http://caocao.oso.com.cn/data_big5.zip にある配列です。編集して oso にダウンロードし、リンクを作成してください。このファイルは数日以内に削除します。)


/*************************************************** *******************
執筆者:caocao
caocao@eastday.com
http://caocao.oso .com.cn

Keyes の協力を得て
Keyes2000 @263.net
http://my-wjl.scu.edu.cn/~Keyes
**************************** ******************************************/
function isbig5($code)
{
if (strlen($code)>=2)
{
$code=strtok($code,"");

if (ord($code[0]) {
return (0);
}
else
{
if (((ord($code[1]) >= 64)&&(ord($code[1]) <= 126))||((ord($code[1]) ]) >= 161)&&(ord($code[1]) {
return (1);
}
else
{
return (0);
}
}
}
else
{
return (0);
}
}

function big5offset($code)
{
if (strlen($code) >= 2)
{
$code=strtok($code,"");
if ((ord($code[1]) >= 64)&&(ord($code[1]) <= 126))
{
return ((ord($code[0]) - 161) * 157 + (ord($code[1]) - 64));
}
if ((ord($code[1]) >= 161)&&(ord($code[1]) <= 254))
{
return ((ord($code[0]) - 161) * 157 + 63 + (ord($code[1]) - 161));
}
}
return (-1);
}

関数 wordtostring($code)
{
return (chr(hexdec(substr($code,0,2))).chr(hexdec(substr($code,2,2))));
}

function big5togb($code)
{
include "data_big5.php";
$output="";
$length=strlen($code);
$code=strtok($code,"");
$idx=0;
while ($idx < $length)
{
$tmpStr=$code[$idx].$code[$idx+1];

if (isbig5($tmpStr))
{
$offset=big5offset($tmpStr);
if (($offset >= 0)||($offset {
$output.=wordtostring($big5order[$offset]);
$idx++;
}
else
{
$output.= $code[$idx];
}
}
else
{
$output.= $code[$idx];
}
$idx++;
}
return ($output);
}
?>  

【本文版权归作者与奥索网共同拥有,如果转下,请注明作者及出处】

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/316579.html技術記事数日前、私は oso フォーラムでそのようなソースプログラムがあるかどうか尋ねましたが、誰も答えませんでした。移植用の Delphi ソース コードを提供してくれた netizen Keyes に感謝します。その発信者は...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。