Traditional Chinese language pack PHP function that converts Simplified Chinese to Traditional Chinese

WBOY
Release: 2016-07-29 08:34:25
Original
1435 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 and make a 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))
                                                                                                                                                                                                        ​(0);
}
else
{
if ((ord($code[1]) <= 161)||(ord($code[1]) >= 254))
{
return (0 ;
}
}
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]);
                                                   
else
{
$output.= $code[ $idx];
}
$idx++;
}
return ($output);
};
?>

The above introduces the Traditional Chinese language pack and the PHP function for converting Simplified Chinese to Traditional Chinese, including the content of the Traditional Chinese language pack. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
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