//Determine encoding
Copy code The code is as follows:
$encode = mb_detect_encoding($q, array('GB2312', 'GBK','UTF-8'));
echo $encode."
";
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);
}
In fact, the mb_detect_encoding function is used. If it is not utf8 encoding, it is converted to utf8 encoding to prevent garbled characters and other situations.
http://www.bkjia.com/PHPjc/780486.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/780486.htmlTechArticle//The code to determine the encoding copy is as follows: $encode = mb_detect_encoding($q, array('GB2312',' GBK','UTF-8')); echo $encode."br/"; if($encode=="GB2312") { $q = iconv("GBK","UTF-8",$q); ...