Thanks to Keyes for providing the Delphi source code for porting. The call method is $ txt = gbtobig5 ($ txt ).
(Note: include "data_gb.php" in the source code; this file is an array, in bytes .)
<?
/*************************************** ********************************
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,). chr (hexdec (substr ($ code ))));
}
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 );
};
?>
[This article is copyrighted by the author and osuo. If you need to reprint it, please indicate the author and its source]