Future King
Future King

Reputation: 3849

file_get_html() returns garbage

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;

enter image description here

Please help. I also tried file_get_contents() but didn't work.

Upvotes: 1

Views: 1283

Answers (1)

vidario
vidario

Reputation: 479

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.

Upvotes: 2

Related Questions