怎么解决php采集乱码?

php 抓取页面乱码

在抓取页面的时候出现类似�������这样乱码解决方法如下

1、转换编码

str=mbconvertencoding(str, “utf-8”, “GBK”);

2、数据经过gzip压缩

curl获取数据的时候设置添加下面的选项:

curl_setopt($ch, CURLOPT_ENCODING, 'gzip');

使用file_get_contents函数需要安装zlib库

$data = file_get_contents("compress.zlib://".$url);/* www.zjkweiqi.cn */

3、获取数据后显示乱码

在顶部增加下面的代码

header("Content-type: text/html; charset=utf-8");

posted @ 2020-08-11 10:19  heiheidou  阅读(240)  评论(0)    收藏  举报