Home >Backend Development >PHP Tutorial >在使用中php会出现file_get_contents的问题解决方法

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-19 12:16:051149browse

没有做过网页抓取类似的功能,file_get_contents这个方法使用的次数也不多。

昨天在phpchina上看见一个网页询问说,使用file_get_contents在抓取souhu blog的时候,出现乱码问题,但是抓取新浪blog的时候却没有

乱码问题。这个问题,我不知道的怎么解决,更不知道为什么。今天,在phpchina上看到lz已经结贴了。答案如下:

获取的头部当中有Content-Encoding: gzip说明内容是GZIP压缩的 解压后就能得到内容了
PHP内置的file_get_contents不支持GZIP 可以试试CURL 好象能处理GZIP

array(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

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