Home >Backend Development >PHP Tutorial >解析php获取字符串的编码格式的方法(函数)_PHP

解析php获取字符串的编码格式的方法(函数)_PHP

WBOY
WBOYOriginal
2016-06-01 12:05:37882browse

如果不清楚字符串的编码格式的话,就可以将这段字符这样检查:
$encode = mb_detect_encoding($string, array("ASCII",'UTF-8′,"GB2312′,"GBK",'BIG5′));
echo $encode;
这样就能知道它是什么编码的了。后续操作还可以为其转码:
if ($encode == “UTF-8″){
$string = iconv("UTF-8″,"GBK",$string);
}

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