问题
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;
Please help. I also tried file_get_contents() but didn't work.
回答1:
Removing 'gzip' from Accept-Encoding will return the un-gzipped response.
See also https://stackoverflow.com/a/10105319/1491542 for ungzip function if you want to handle it yourself.
来源:https://stackoverflow.com/questions/17041202/file-get-html-returns-garbage