A few days ago I asked in the Oso forum whether this source program, no one reply. Finally decided to transplant a function like this, thanks to the Netizen Keyes provides the Delphi source code for transplant. The method is called $TXT=BIG5TOGB ($txt).
(Note: the include "data_big5.php" in the source code; This file is an array, in Http://caocao.oso.com.cn/data_big5.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 Isbig5 ($code)
{
if (strlen ($code) >=2)
{
$code =strtok ($code, "");
if (Ord ($code [0]) < 161)
{
return (0);
}
Else
{
if ((Ord ($code [1]) >= && (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]) >=) && (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 + + (ord ($code [1])-161));
}
}
Return (-1);
}
function 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 <= 14757))
{
$output. =wordtostring ($big 5order[$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"
http://www.bkjia.com/PHPjc/316579.html www.bkjia.com true http://www.bkjia.com/PHPjc/316579.html techarticle a few days ago I asked in the Oso forum whether this source program, no one reply. Finally decided to transplant a function like this, thanks to the Netizen Keyes provides the Delphi source code for transplant. Its callers ...