//判斷編碼
復制代碼 代碼如下:
$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編碼,防止出現亂碼等情況。