Home >Backend Development >PHP Tutorial >请教curl采集ebay乱码怎样解决?

请教curl采集ebay乱码怎样解决?

WBOY
WBOYOriginal
2016-06-23 13:47:081146browse

各位朋友,我现在使用curl采集信息,发现采集ebay店铺信息时老是显示为乱码,比如:

$url="http://stores.ebay.com/sportingamerica/";
$caiji=curl_get_contents($url);
print_r($caiji);
哪位朋友能否解释下?谢谢!

function curl_get_contents($url)
{
    $ch = curl_init();   
    curl_setopt($ch, CURLOPT_URL, $url);              
    //curl_setopt($ch,CURLOPT_HEADER,1);            
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);          
    curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);      
    curl_setopt($ch, CURLOPT_REFERER,_REFERER_);       
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);     
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        
    $r = curl_exec($ch);   
    curl_close($ch);   
    return $r;   
}

编码应该没有问题,我的php文件编码是utf-8,ebay的页面编码也是utf-8的啊。


回复讨论(解决方案)

数据被 gzip 压缩了

设置这个    curl_setopt($ch, CURLOPT_ENCODING, 1); 
或读回后  echo gzdecode($caiji);

你可以设置获取后的返回代码编码格式为text/utf8格式,这样看看可不可以。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:thinkphpNext article:Azure网站上的PHP ? 架构