
PHP中繁体中文转换成简体中文
---------------------------------------------------------------
<?
function isbig5($code)
{
if (strlen($code)>=2)
{
$code=strtok($code,"");
if (ord($code[0]) < 161)
{
return (0);
}
else
{
if (((ord($code[1]) >= 64)&&(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]) >= 64)&&(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 + 63 + (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($big5order[$offset]);
$idx++;
}
else
{
$output.= $code[$idx];
}
}
else
{
$output.= $code[$idx];
}
$idx++;
}
return ($output);
}
?>
我们学校的网站和香港的一个交换数据库,遇到了类似的问题,上面是我写的一个函数。写的时候是参考了函数手册完成的,function big5togb($code) 是主函数。
发布日期:2021-10-21 03:38:22
浏览次数:10
分类:技术文章
本文共 1358 字,大约阅读时间需要 4 分钟。
由于是拷贝的别人数据库中的东西,是繁体。有很多好东西不舍得放掉怎么把它转换一下啊。各位救命啊。---------------------------------------------------------------
<?
function isbig5($code)
{
if (strlen($code)>=2)
{
$code=strtok($code,"");
if (ord($code[0]) < 161)
{
return (0);
}
else
{
if (((ord($code[1]) >= 64)&&(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]) >= 64)&&(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 + 63 + (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($big5order[$offset]);
$idx++;
}
else
{
$output.= $code[$idx];
}
}
else
{
$output.= $code[$idx];
}
$idx++;
}
return ($output);
}
?>
我们学校的网站和香港的一个交换数据库,遇到了类似的问题,上面是我写的一个函数。写的时候是参考了函数手册完成的,function big5togb($code) 是主函数。
转载地址:https://blog.csdn.net/WapWeb/article/details/29458 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2023年03月18日 18时10分17秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
最新文章
pip3升级10.0后cannot import name 'main'
2019-12-24 14:49:06
刚装完系统干嘛—献给自己!
2019-12-24 14:49:07
django创建超级用户(createsuperuser)后报错: 'WSGIRequest' object has no attribute 'user'
2019-12-24 14:49:07
JDK动态代理原理解析
2019-12-24 14:49:05
springcloud负载均衡之Ribbon
2019-12-24 14:49:05
spark之卡方特征选择(ChiSqSelector)
2019-12-24 14:49:06
Cglib代理解密
2019-12-24 14:49:06
G1GC(garbage first)
2019-12-24 14:49:06
面试-Python 装饰器
2019-12-24 14:49:04
mac OS 安装 xgboost(最新解决方案)
2019-12-24 14:49:04
面试-java多线程实现方式及对比
2019-12-24 14:49:04
Windows7+JDK1.8环境配置最简单教程
2019-12-24 14:49:04
Spring4.2.3与Quartz2.3执行定时任务整合
2019-12-24 14:49:04
SSM框架史上最简单快速搭建
2019-12-24 14:49:04
安卓 上传头像 相机相册 剪裁
2019-12-24 14:49:03
Android网络判断
2019-12-24 14:49:03
GreenDao的简单使用
2019-12-24 14:49:03
Retrofit+RxJava 的结合使用
2019-12-24 14:49:03
百分比布局通过代码设置属性
2019-12-24 14:49:03
Viewpager自定义轮播特效(仿京东超市 休闲零食 头部轮播)
2019-12-24 14:49:03