关于curl抓取回来的网页中中文乱码的有关问题

WBOY
Release: 2016-06-13 10:48:11
Original
1017 people have browsed it

关于curl抓取回来的网页中中文乱码的问题!
目前使用这个函数进行转码:
function safeEncoding($str){
$code=mb_detect_encoding($str,array('ASCII','GB2312','GBK','UTF-8'));//检测字符串编码
if($code=="CP936"){
$result=$str;
}
else{
//$result=mb_convert_encoding($str,'UTF-8',$code);//将编码$code转换为utf-8编码
$result=iconv($code,"UTF-8",$str);
}
  return $result;
}
可是还是有问题,遇到有些明明charset写着gb2312的抓回来还是乱码,请教高手,curl到底该怎么全面的进行转码呢?就是把gbk,gb2312等网页常用格式转成utf8的。

------解决方案--------------------
把你的文件编码转换下试试!
------解决方案--------------------
EUC-CN是GB 2312最常用的表示方法。浏览器编码表上的“GB2312”,通常都是指“EUC-CN”表示法。
这不是关键!
你需要的是 把gbk,gb2312等网页常用格式转成utf8的
而你的代码正好没有这样做

if(! mb_check_encoding($str, 'utf-8')) {
$str = mb_convert_encoding($str,'UTF-8','gbk');
}

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!