抓取页面出现乱码

hykeda7年前PHP1009

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

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

相关文章

php json_encode输出空白问题

php json_encode输出空白问题

例如这样的一段转json出现空白: echo json_encode(array('error' => '0', 'message' => '没有错误')); var_dump(js...

file_get_contents("php://input")的使用方法

$data = file_get_contents("php://input"); php://input 是个可以访问请求的原始数据的只读流。 POST 请求的情况下,最好使用 php:/...

PHP限制ip以及IP段是否允许访问,以及对ip子网的理解

php 如何限制ip访问:// 判断ip是否被允许 function isIpBlocked($clientIP,$blockedIPs) {   ...

discuzX3.2 用户注册接口代码

新建一个php文件在根目录,例:test.php test.php 具体内容: error_reporting(0); require_once './source/class/clas...

file_get_contents和curl出现400 Bad Request问题

我在使用这两个函数抓取数据的时候出现了400错误,一开始以为是http和https的问题,以为https证书问题,忽略证书后还是报400,但是输入百度的网址都正常。 其实是url参数...

百度经纬度和火星坐标转换

<?php     //GCJ-02...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。