您的位置:首页 > 网络编程 > PHP

网页文字简繁转换函数

日期:2005-11-16 00:00: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);
?>
More..素材图片 Picture Navigation
PHP热门 Class Hot
PHP推荐 Class Commend
版权所有:中国网站资源 2005- 未经授权禁止复制或建立镜像 This Site Tech:XHTML+DIV+CSS+Javascript
CopyRight ® 2005- www.chinaddv.com online services. all rights reserved. ICP06016627
Optimized to 1024x768 to Firefox,Netscape,Opera,MS-IE6+.