php 使用file_get_contents的问题
2010-11-02 13:14
826 查看
没有做过网页抓取类似的功能,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"
}
复制代码
再次多谢lz提的问题,已经这位仁兄的答案。让我又学到了东西。
phpchina中帖子的连接为:http://bbs.phpchina.com/thread-199524-1-1.html
看样子,phpchina csdn 这样的论坛还是要多多看看的。要学的东西还是很多的。
昨天在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"
}
复制代码
再次多谢lz提的问题,已经这位仁兄的答案。让我又学到了东西。
phpchina中帖子的连接为:http://bbs.phpchina.com/thread-199524-1-1.html
看样子,phpchina csdn 这样的论坛还是要多多看看的。要学的东西还是很多的。
相关文章推荐
- file_put_contents以及file_get_contents的用法与在使用过程中遇到的问题(PHP学习)
- PHP使用file_get_contents或curl请求https的域名内容为空或Http 505错误的问题排查方法
- file_put_contents以及file_get_contents的用法与在使用过程中遇到的问题(PHP学习)
- PHP中使用file_get_contents抓取网页中文乱码问题解决方法
- PHP中使用file_get_contents()抓取网页乱码的问题
- PHP中使用file_get_contents抓取网页中文乱码问题解决方法
- file_get_contents("php://input")的使用方法
- PHP使用curl替代file_get_contents
- 解决PHP中file_get_contents抓取网页中文乱码问题
- file_get_contents("php://input")的使用方法
- file_get_contents("php://input")的使用方法
- PHP使用fopen与file_get_contents读取文件实例分享
- PHP如何响应移动端(android or ios)的post请求(使用file_get_contents)
- file_get_contents("php://input")的使用方法
- PHP中使用file_get_contents post数据代码例子
- 解析PHP中的file_get_contents获取远程页面乱码的问题
- file_get_contents("php://input")的使用方法
- file_get_contents("php://input")的使用方法
- php 使用file_get_contents读取大文件的方法