A few days ago, I asked the oso Forum if there was any source code and no one replied. Finally, I made up my mind to transplant such a function and thanked the netizen Keyes for providing the Delphi source code for transplantation. The call method is $ txt = big5togb ($ txt ).
(Note: In the source code, include "data_big5.php"; 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 isbig5 ($ code)
{
If (strlen ($ code)> = 2)
{
$ Code = strtok ($ code ,"");
If (ord ($ code [0]) <161)
{
Return (0 );
}
Else
{
If (ord ($ code [1])> = 64) & (ord ($ code [1]) <= 126 )) | (ord ($ code [1])> = 161) & (ord ($ code [1]) <= 254 )))
{
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 );
}
Function wordtostring ($ code)
{
Return (chr (hexdec (substr ($ code,). chr (hexdec (substr ($ code ))));
}
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 <= 14757 ))
{
$ Output. = wordtostring ($ big5order [$ 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]