解析php获取字符串的编码格式的方法(函数)
如果不清楚字符串的编码格式的话,就可以将这段字符这样检查:
$encode = mb_detect_encoding($string, array("ASCII",'UTF-8′,"GB2312′,"GBK",'BIG5′));
echo $encode;
这样就能知道它是什么编码的了。后续操作还可以为其转码:
if ($encode == “UTF-8″){
$string = iconv("UTF-8″,"GBK",$string);
}
$encode = mb_detect_encoding($string, array("ASCII",'UTF-8′,"GB2312′,"GBK",'BIG5′));
echo $encode;
这样就能知道它是什么编码的了。后续操作还可以为其转码:
if ($encode == “UTF-8″){
$string = iconv("UTF-8″,"GBK",$string);
}
相关推荐
amberom 2020-08-03
zlsdmx 2020-07-05
文山羊 2020-10-20
Tristahong 2020-10-14
stulen 2020-08-15
xiaoseyihe 2020-08-11
fengzhiwu 2020-08-01
pythonxuexi 2020-07-30
leoaran 2020-07-21
littie 2020-07-19
kkpiece 2020-07-08
银角大王 2020-07-05
yjsflxiang 2020-07-04
shonmark 2020-06-27
chinawangfei 2020-06-16
liusarazhang 2020-06-14
xiaobaif 2020-06-14