php 判断网页是否是utf8编码的方法
程序员文章站
2023-11-28 22:00:28
//判断编码复制代码 代码如下:$encode = mb_detect_encoding($q, array('gb2312','gbk','utf-8'));echo $...
//判断编码
$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编码,防止出现乱码等情况。
复制代码 代码如下:
$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编码,防止出现乱码等情况。
上一篇: HTML5 Canvas绘制五星红旗