PHP method to determine whether a web page is utf8 encoded_PHP tutorial

WBOY
Release: 2016-07-13 10:28:49
Original
810 people have browsed it

//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.

www.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); ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template