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];
////////////////////////////////////////////
//作者: 网络骑士 //
//联系方式:[email protected] //
//所用技术:php //
//完成时间:2002-05-12 //
///////////////////////////////////////////
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);
}
?>
例如简体就是<meta http-equiv="content-Type" content="text/html"; charset=gb123>
<meta http-equiv="Content-Language" content="zh-CN">说明所用语言及文字...
繁体:<meta http-equiv="content-type" content="text/html; charset=Big5">
用JS的好处是,在你的网站上如果有这样的链接"简体版|繁体版",只要点链接,很快就换了。速度上可以接受,况且又不是做研究,没必要哪个字都转换,只要能在执行效率和可用性以及实用性上平衡一下,这就是好的方案,最优的解决途径。
js是怎么做的??能不能贴点代码参考参考