PHP function to convert Simplified Chinese to Traditional Chinese_PHP tutorial

WBOY
Release: 2016-07-21 16:02:16
Original
1907 people have browsed it

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]

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316581.htmlTechArticleThanks 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, in http...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template