文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>网页文字简繁转换函数

网页文字简繁转换函数

时间:2007-02-17  来源: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); }; ?>

使用方法:

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

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

3. 对目标字段套用函数,实现格式化输出
<?php echo gbtobig5($txt);
?>
php爱好 者站 http://www.phpfans.net php基础|php进阶|php模板.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载