收 藏 投 稿 繁 体 RSS 
站长吧-中国站长学习与交流的网站
首 页 运 营 学 院 建 站 论 坛
Web master8.net  
 网站运营  
  欢迎在本站发布信息,在线投递稿件请点这里。编辑QQ:4908220,欢迎联系交流。
业界动态 创业故事 推广研究 策划盈利 电子商务 企业平台
  站长工具
SEO查询 Whois查询 Pr查询 域名查询 IP查询 网页编辑器
 建站服务  
  如有建站意向,请尽快联系我们,以便安排时间... 建站服务 QQ4908220 QQ:4908220
作品展示 服务范围 服务流程 服务报价 联系方式 付款方式
文章正文  » 您的当前位置: 首页 >> 学院 >> 程序开发 >> PHP
简体中文与繁体中文互转的PHP函数
  来源:互联网 | 时间:2005-10-04 | 浏览:   相关评论 | 报告错误 | 发布文章
【字号: | | 】 【背景色 杏仁黄 秋叶褐 胭脂红 芥末绿 天蓝 雪青 灰 银河白(默认色)
简体中文转换为繁体中文的PHP函数
<? 
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); 
}; 
?> 


繁体中文转换为简体中文的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); 

?> 
master8
  • 上一篇:关于session的几个补充函数
  • 下一篇:万维网创始人博客处女秀

  • 我要投稿  打印本文  推荐本文  加入收藏  返回顶部  关闭窗口
    搜模板(www.somoban.com) 原创网站模板交易平台
    阿里妈妈再掀疯狂采购风,网站广告位严重告急,急召天下站长
    基于PHP+MySQL的整站、模块、插件开发等或者按需求实现相应功能;
基于各PHP主流建站系统CMS,BBS,BLOG等的模板定制,完全手写代码;
整站数据迁移或备份恢复;网页代码优化、重构;整站常规SEO优化;网站技术支持;
点击了解详情...
    站长论坛
    • 验证码: