首页 >后端开发 >php教程 >PHP判断变量内容是什么编码(gbk?utf-8) mb_detect_encoding

PHP判断变量内容是什么编码(gbk?utf-8) mb_detect_encoding

ringa_lee
ringa_lee原创
2018-05-14 16:30:102578浏览
mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK"); 获取编码类型
function convToUtf8($str) {
    if( mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK")!="UTF-8" ) {//判断是否不是UTF-8编码,如果不是UTF-8编码,则转换为UTF-8编码
        return  iconv("gbk","utf-8",$str);
    } else {
        return $str;
    }
}

复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn