网页文字简繁转换函数
<?phpfunction 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. 对目标字段套用函数,实现格式化输出
========================
请给分吧!我要150分
<?phpfunction 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. 对目标字段套用函数,实现格式化输出
========================
请给分吧!我要150分
找不到啦!不好意思!
没有提供
显示时,用UTF8
你必须有一张简繁体字型的对照表,这张表可从gbk码表中构造,可放在数组或库中。也可放在共享内存中
检索起来应该很快,不会象你说的那样慢
放在数组中时应这样组织:
'乱' => '亂',
即以简体字做关联键,以繁体字做值
替换时
echo preg_replace_callback("/[\x80-\xff]./",'charset',$text);function charset($ch) {
global $word; //$word为简繁对照表
reuurn word[$ch];
}
两套语言包???我不是很懂呀~你指的不会是做两套页面吧?这个网站需要所有用户发表的帖子可以任意用简体中文或者繁体中文显示,而且可以随时转换。我只找到了这两种方法,如果有什么更好的方法请赐教~多谢~
这就不是我的想法了。我的意思是用模板。当然你说的那个功能,就必须用字符对照转换表了。