yanwong / ganon

Automatically exported from code.google.com/p/ganon
0 stars 0 forks source link

file_get_dom cannot pass arguments to file_get_contents #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Some sites serve content differently, or not at all *cough*Facebook*, depending 
on the user_agent string passed in the headers. As the function is now, the 
user would have to hard-code these extra parameters in. If you change the 
file_get_dom function to the following:

function file_get_dom($file, $return_root = true, $use_include_path = false, 
$context = null) {
    $f = file_get_contents($file, $use_include_path, $context);
    return (($f === false) ? false : str_get_dom($f, $return_root));
}

You could set this on a case-by-case basis like so:

$opts = array('http' => array('method' => 'GET', 'header' => "Accept-language: 
en\r\n", 'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; 
rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16'));
$context = stream_context_create($opts);
$tmp_discussion_html = file_get_html($some_url, true, false, $context);

Original issue reported on code.google.com by thevelem...@gmail.com on 29 Apr 2011 at 10:45

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r59.

Original comment by niels....@gmail.com on 4 May 2011 at 6:41

GoogleCodeExporter commented 8 years ago
Thank you very much for reporting! I applied your fix.

Original comment by niels....@gmail.com on 4 May 2011 at 6:42