php 无法用file_get_contents,php file_get_contents函数的使用问题

使用file_get_contents抓取sohu blog时,出现乱码问题,但是抓取新浪blog时没有问题。

解决方法:

由于获取的页面头部有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"

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值