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

  

原文地址:https://www.cnblogs.com/68xi/p/13455392.html