PHP如何将gb2312网页内的中文转换成utf-8
现在我这里只很多网页都是以gb2312编码的,
我要将它们都转换成utf-8,
请问有什么方法,我在网上找到是这样的代码,但好像不行:
PHP code
用这的函数生成的还是乱码
我要将它们都转换成utf-8,
请问有什么方法,我在网上找到是这样的代码,但好像不行:
PHP code
function gb2utf8($gb) /* Program writen by sadly modified by agun */ { 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,7,6); $ret= " "; $utf8= " "; while($gb) { if (ord(substr($gb,0,1))> 127) { $this1=substr($gb,0,2); $gb=substr($gb,2,strlen($gb)); $utf8=u2utf8(hexdec($codetable[hexdec(bin2hex($this1))-0x8080])); for($i=0;$i <strlen($utf8);$i+=3) $ret.=chr(substr($utf8,$i,3)); } else { $ret.=substr($gb,0,1); $gb=substr($gb,1,strlen($gb)); } } return $ret; }
用这的函数生成的还是乱码
作者: allix123 发布时间: 2011-05-29
这个是什么年代的帖子?不会还在用php4吧?
iconv("GBK","UTF-8",$gb);
另外输出header charset要设为utf-8
iconv("GBK","UTF-8",$gb);
另外输出header charset要设为utf-8
作者: snmr_com 发布时间: 2011-05-29