Thank the Netizen Keyes provides the Delphi source code which the transplant uses. The method is called $txt=gbtobig5 ($txt).
(Note: the include "data_gb.php" in the source code; This file is an array, in Http://caocao.oso.com.cn/data_gb.zip, please edit the download to Oso, do a link, because this file I will be deleted 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 (0);
}
Else
{
return (1);
}
}
}
Else
{
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 + +;
}
Else
{
$output. = $code [$idx];
}
}
Else
{
$output. = $code [$idx];
}
$idx + +;
}
return ($output);
};
?>
"The copyright of this article is owned by the author and house Orso near net, if need to reprint, please specify the author and source"
The above introduces the traditional Chinese language pack Simplified Chinese to Traditional Chinese PHP function, including the traditional Chinese language package aspects of the content, I hope that the PHP tutorial interested in a friend helpful.