繁体中文
设为首页
加入收藏
当前位置:PHP技术首页 >> 文件处理 >> 网页文字简繁转换函数

网页文字简繁转换函数

2005-01-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:   使用方法: 1. 将以上代码另存为gbtobig5.php 2. 在需要的页面引入gbtobig5.php 3. 对目标字段套用函数,实现格式化输出
关键字:简繁 函数 文字 网页

  

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

3. 对目标字段套用函数,实现格式化输出

责任编辑:admin
相关文章