动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   PHP → 阅读文章

 网页文字简繁转换函数

作者来源: 
阅读 数 656 人次 , 2006-2-16 14:35:00 



<? 
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); 
}; 
?>




使用方法:

1. 将以上代码另存为gbtobig5.php

2. 在需要的页面引入gbtobig5.php
<?php incude('gbtobig5.php'); ?>

3. 对目标字段套用函数,实现格式化输出
<?php echo gbtobig5($txt);
?>
  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:转义符使用小结
· 下一篇:PHP的十个高级技巧
· PHP和MySQL开发的8个技巧
· 十天学会php之第八天
· “在phpMyAdmin使用用户口令登陆”补充
· PHP中 ADODB 类库介绍(二)
· 用PHP发送MIME邮件(四)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077