file_get_html() returns garbage

£可爱£侵袭症+ 提交于 2020-02-05 13:06:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!