php curl函数采集网页出现乱码问题解决方法
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');
页面编码问题
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网页标题中文乱码如何解决