您好,欢迎访问一九零五行业门户网

在使用中php会出现file_get_contents的问题解决方法

没有做过网页抓取类似的功能,file_get_contents这个方法使用的次数也不多。
昨天在phpchina上看见一个网页询问说,使用file_get_contents在抓取souhu blog的时候,出现乱码问题,但是抓取新浪blog的时候却没有
乱码问题。这个问题,我不知道的怎么解决,更不知道为什么。今天,在phpchina上看到lz已经结贴了。答案如下:
获取的头部当中有content-encoding: gzip说明内容是gzip压缩的 解压后就能得到内容了
php内置的file_get_contents不支持gzip 可以试试curl 好象能处理gziparray(11) {
 [0]=>
 string(15) http/1.1 200 ok
 [1]=>
 string(35) content-type: text/html;charset=gbk
 [2]=>
 string(17) connection: close
 [3]=>
 string(13) server: nginx
 [4]=>
 string(35) date: fri, 29 oct 2010 00:36:51 gmt
 [5]=>
 string(26) vary: host,accept-encoding
 [6]=>
 string(14) pragma: public
 [7]=>
 string(26) cache-control: max-age=300
 [8]=>
 string(38) expires: fri, 29 oct 2010 00:41:53 gmt
 [9]=>
 string(22) content-encoding: gzip
 [10]=>
 string(14) fss-cache: hit
}
file_get_contents超时问题及解决方案
http://tech.cncms.com/web/php/111869.html
其它类似信息

推荐信息