抓取页面出现乱码
在抓取页面的时候出现类似�������这样乱码解决方法如下
1、转换编码
str=mbconvertencoding(str=mbconvertencoding(str, “utf-8”, “GBK”);
2、数据经过gzip压缩
curl获取数据的时候设置添加下面的选项:
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
- 1
- 2
使用file_get_contents函数需要安装zlib库 $data = file_get_contents("compress.zlib://".$url);
- 1
- 2
3、获取数据后显示乱码
在顶部增加下面的代码 header("Content-type: text/html; charset=utf-8");