教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php curl函数采集网页出现乱码问题解决方法

php curl函数采集网页出现乱码问题解决方法

发布时间:2018-09-30   编辑:jiaochengji.com
教程集为您提供php curl函数采集网页出现乱码问题解决方法等资源,欢迎您收藏本站,我们将为您提供最新的php curl函数采集网页出现乱码问题解决方法资源
curl乱码有两个方面的原因一个是因为我们采集页面的php页面编码与远程文档编码不致导致的,另一种可能是页面进入了gzip压缩传输导致的,那么我们要如何解决这些问题呢?

gzip压缩传输导致乱码

今天在采集京东的时候发现返回的数据是乱码,网上说可能和压缩有关,看了一下京东的头信息的确进行gzip加密,好吧,那就解压吧

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1824')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1824>

$return = gzdecode($return); //将return的字符进行解码

另一种解决办法

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


页面编码问题

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3276')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3276>

mb_convert_encoding($str, 'utf-8', 'GBK,UTF-8,ASCII');就行了

您可能感兴趣的文章:
php 获取远程网页内容简单函数
php curl函数采集网页出现乱码问题解决方法
php下载css中图片函数
php中file_get_contents获取网页乱码解决办法
php中curl、fsocket、file_get_content函数比较
failed to open stream: HTTP request failed
php读取远程文件的三种方法分享
解决Phpmyadmin导入导出时中文乱码的问题
php file_get_contents函数抓取页面信息的代码
php网页标题中文乱码如何解决

[关闭]
~ ~