Home >Backend Development >PHP Tutorial >PHP determines what encoding the variable content is (gbk? utf-8) mb_detect_encoding

PHP determines what encoding the variable content is (gbk? utf-8) mb_detect_encoding

ringa_lee
ringa_leeOriginal
2018-05-14 16:30:102582browse
mb_detect_encoding($str,"UTF-8, ISO-8859-1, GBK"); Get the encoding type
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;
    }
}

Copy code


Statement:
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