解决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);

  3、获取数据后显示乱码

在顶部增加下面的代码

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

  

posted @ 2020-08-07 21:40  圆柱模板  阅读(317)  评论(0编辑  收藏  举报