这个对你也许有用!^_^
简繁体转换的实现
<?
function gb2big5($str) {
global $_gb_big5_;
$leng = strlen($str)-1;
for($i = 0; $i<$leng; $i++){
$h = ord($str&i;
if($h>=160){
$l = ord($str&i+1;
$gb=($h==161 && $l==64)?" " : substr($_gb_big5_, ($h-160)*510+($l-1)*2, 2);
$str&i; = $gb[0];
$str&i+1; = $gb[1];
$i++;
}
}
return $str;
}
?>
其中:
$gb_big5_ 保存着big5 的字库对照表
$str 为要转化的字符串
简繁体转换的实现
<?
function gb2big5($str) {
global $_gb_big5_;
$leng = strlen($str)-1;
for($i = 0; $i<$leng; $i++){
$h = ord($str&i;
if($h>=160){
$l = ord($str&i+1;
$gb=($h==161 && $l==64)?" " : substr($_gb_big5_, ($h-160)*510+($l-1)*2, 2);
$str&i; = $gb[0];
$str&i+1; = $gb[1];
$i++;
}
}
return $str;
}
?>
其中:
$gb_big5_ 保存着big5 的字库对照表
$str 为要转化的字符串
有繁体,简体版,如果要综合判断,需要比对语义,所以,最好数据库里面就存一种内码,到时候转换。
所以,你要做的就两件事:
一、如果得到该字的内码,不知道PHP有没有直接的这样的函数?
二、繁体字的内码表,这个只能去找有关的文档了。
{
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 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);
}
}