GB2312 转换为 unicode 的函数 // Program by sadly (www.phpx.com) function gb2unicode($gb) { if(!trim($gb)) return $gb; $filename="gb2312.txt"; $tmp=file($filename); $codetable=array(); while(list($key,$value)=each($tmp)) $codetable[hexdec(substr($value,0,6))]=substr($value,9,4); $utf=""; while($gb) { if (ord(substr($gb,0,1))>127) { $this=substr($gb,0,2); $gb=substr($gb,2,strlen($gb)); $utf.="".$codetable[hexdec(bin2hex($this))-0x8080].";"; } else { $gb=substr($gb,1,strlen($gb)); $utf.=substr($gb,0,1); } } return $utf; } ?> 这个函数需要一个gb2312的码表文件,这里下载 ftp://ftp.unicode.org/Public/MAPPINGS/EASTASIA/GB/GB2312.TXT 请注意文件名大小写的问题。
GB2312转换unicode的函数 |