php 简转繁体,PHP_简体中文转换为繁体中文的PHP函数,感谢网友Keyes提供移植用的Delph - phpStudy...

简体中文转换为繁体中文的PHP函数

感谢网友Keyes提供移植用的Delphi源代码。其调用方式为$txt=gbtobig5($txt)。

(注:源代码中的include "data_gb.php";这个文件在就是一个数组,在http://caocao.oso.com.cn/data_gb.zip,请编辑下载到oso上,做一个链接,因为这个文件我过几天就要删除了。)

/***********************************************************************

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 (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 < $length)

{

$tmpStr=$code[$idx].$code[$idx+1];

if (isgb($tmpStr))

{

$offset=gboffset($tmpStr);

if (($offset >= 0)||($offset <= 8177))

{

$output.=wordtostring($gborder[$offset]);

$idx++;

}

else

{

$output.= $code[$idx];

}

}

else

{

$output.= $code[$idx];

}

$idx++;

}

return ($output);

};

?>

【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】相关阅读:

Linux系统下监控和调整机器温度

IIS使用十大原则

在PHP里得到前天和昨天的日期的代码

HTML中使用空格排版的问题

phpBB BBcode处理的漏洞

Step1数据系统技术(3.使用浏览器Cache和http状态码304实现的客户端缓存)

动态载入/删除/更新外部 JavaScript/Css 文件的代码

Oracle如何回收回滚段空间

系统设置--moouseconfig

javascript取屏幕信息的一些对象

Linux系统下设置Tomcat自启动

JavaScript 给汉字排序实例代码

jQuery图片预加载 等比缩放实现代码

使用 mailman 架设邮件列表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值