php 判断网页是否是utf8编码的方法

yipeiwu_com6年前PHP代码库
//判断编码
复制代码 代码如下:

$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实现截取指定长度

PHP语言: 根据中文裁减字符串复制代码 代码如下:function cutstr($string,$length, $dot = ' ...') {  if (strlen(...

PHP 删除一个目录及目录下的所有文件的函数代码

复制代码 代码如下: /***** *@dir - Directory to destroy *@virtual[optional]- whether a virtual directo...

zend Framework中的Layout(模块化得布局)详解

1.首先修改application配置文件resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"指定布局文件的...

解决文件名解压后乱码的问题 将文件名进行转码的代码

复制代码 代码如下: <?php $a=zip_open('other.zip'); while ($e=zip_read($a)){ $fz = zip_entry_filesi...

php逐行读取txt文件写入数组的方法 原创

本文实例讲述了php逐行读取txt文件写入数组的方法。分享给大家供大家参考。具体如下: 假设有user.txt文件如下: user01 user02 user03 user04 us...