file_get_html()返回垃圾 [英] file_get_html() returns garbage
本文介绍了file_get_html()返回垃圾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用simple_html_dom解析器. 以下代码返回垃圾输出:
I am using a simple_html_dom parser. The following code is returning garbage output:
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n".
"Accept-Encoding: gzip, deflate\r\n".
"Accept-language: en-US,en;q=0.5\r\n" .
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n".
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$html = file_get_html("http://freepsdfiles.net/",false,$context);
echo $html;
请帮助.我也尝试了file_get_contents()但没有用.
Please help. I also tried file_get_contents() but didn't work.
推荐答案
从接受编码"中删除"gzip"将返回未压缩的响应.
Removing 'gzip' from Accept-Encoding will return the un-gzipped response.
如果要处理ungzip功能,另请参见 https://stackoverflow.com/a/10105319/1491542 它自己.
See also https://stackoverflow.com/a/10105319/1491542 for ungzip function if you want to handle it yourself.
这篇关于file_get_html()返回垃圾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文