Home >Backend Development >PHP Tutorial >PHP function to convert Simplified Chinese to Traditional Chinese_PHP tutorial
Thanks to netizen Keyes for providing the Delphi source code for transplantation. The calling method is $txt=gbtobig5($txt).
(Note: include "data_gb.php" in the source code; this file is an array at http://caocao.oso.com.cn/data_gb.zip. Please edit and download it to oso to make an Link, because I will delete this file in a few days)
/***********************************************************************
Written by caocao
caocao@eastday.com
http://caocao.oso.com.cn
With the help of Keyes
Keyes2000@263.net
http://my-wjl.scu.edu.cn/~Keyes
***********************************************************************/
function isgb($code)
{
if (strlen($code)>=2)
{
$code=strtok($code,"");
if ((ord($code[0]) < 161) ||(ord($code[0]) >= 247))
{
return (0);
}
else
{
if ((ord($ code[1]) <= 161)||(ord($code[1]) >= 254))
{
return (1); >function gboffset($code)
{
if (strlen($code) >= 2)
{
$code=strtok($code,"");
return ( (ord($code[0]) - 161) * 94 + (ord($code[1]) - 161));
}
else
{
return(-1);
}
}
function wordtostring($code)
{
return (chr(hexdec(substr($code,0,2))).chr(hexdec(substr ($code,2,2))));
}
function gbtobig5($code)
{
include "data_gb.php";
$output="" ;
$length=strlen($code);
$code=strtok($code,"");
$idx=0;
while ($idx < $length)
{
$tmpStr=$code[$idx].$code[$idx+1];
if (isgb($tmpStr))
{
$offset=gboffset( $tmpStr);
if (($offset >= 0)||($offset <= 8177))
{
$output.=wordtostring($gborder[$offset]);
$idx++; 🎜> {
$output.= $code[$idx];
}
$idx++;
}
return ($output);
};
?>
[The copyright of this article is jointly owned by the author and Aosuo.com. If you need to reprint, please indicate the author and source]