Posted in PHP onJune 06, 2014
//判断编码
$encode = mb_detect_encoding($q, array('GB2312','GBK','UTF-8')); echo $encode."<br/>"; if($encode=="GB2312") { $q = iconv("GBK","UTF-8",$q); } else if($encode=="GBK") { $q = iconv("GBK","UTF-8",$q); } else if($encode=="EUC-CN") { $q = iconv("GBK","UTF-8",$q); } else//CP936 { //$q = iconv("GB2312","UTF-8",$q); }
其实就是利用了mb_detect_encoding函数,如果不是utf8编码就转换为utf8编码,防止出现乱码等情况。
php 判断网页是否是utf8编码的方法
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@