最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
简体中文转换为繁体中文的PHP函数
时间:2022-07-02 10:08:07 编辑:袖梨 来源:一聚教程网
感谢网友Keyes提供移植用的Delphi源代码。其调用方式为$txt=gbtobig5($txt)。
(注:源代码中的include "data_gb.php";这个文件在就是一个数组,在http://caocao.**oso.c*om.cn/data_gb.zip,请编辑下载到oso上,做一个链接,因为这个文件我过几天就要删除了。)
/***********************************************************************
Written by caocao
[email protected]
http://caocao.o**so.c*om.cn
With the help of Keyes
[email protected]
http://my-wjl.s*cu*.ed*u.cn/~Keyes
***********************************************************************/
function isgb($code)
{
if (strlen($code)>=2)
{
$code=strtok($code,"");
if ((ord($code[0]) = 247))
{
return (0);
}
else
{
if ((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,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 {
$tmpStr=$code[$idx].$code[$idx+1];
if (isgb($tmpStr))
{
$offset=gboffset($tmpStr);
if (($offset >= 0)||($offset {
$output.=wordtostring($gborder[$offset]);
$idx++;
}
else
{
$output.= $code[$idx];
}
}
else
{
$output.= $code[$idx];
}
$idx++;
}
return ($output);
};
?>
(注:源代码中的include "data_gb.php";这个文件在就是一个数组,在http://caocao.**oso.c*om.cn/data_gb.zip,请编辑下载到oso上,做一个链接,因为这个文件我过几天就要删除了。)
/***********************************************************************
Written by caocao
[email protected]
http://caocao.o**so.c*om.cn
With the help of Keyes
[email protected]
http://my-wjl.s*cu*.ed*u.cn/~Keyes
***********************************************************************/
function isgb($code)
{
if (strlen($code)>=2)
{
$code=strtok($code,"");
if ((ord($code[0]) = 247))
{
return (0);
}
else
{
if ((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,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 {
$tmpStr=$code[$idx].$code[$idx+1];
if (isgb($tmpStr))
{
$offset=gboffset($tmpStr);
if (($offset >= 0)||($offset {
$output.=wordtostring($gborder[$offset]);
$idx++;
}
else
{
$output.= $code[$idx];
}
}
else
{
$output.= $code[$idx];
}
$idx++;
}
return ($output);
};
?>
相关文章
- 哔咔漫画app官网入口-哔咔漫画网页版官方直达 03-12
- 苹果18手机什么时候上市-预计价格多少-苹果18手机图片 03-12
- b站网页版登录入口-哔哩哔哩官网登录入口 03-12
- twitter官网网页版-twitter官方登录界面 03-12
- 谜漫画最新版下载安卓安装包-谜漫画安卓版官方下载地址入口 03-12
- manwa2漫蛙漫画官网-漫蛙manwa2漫画站 03-12