Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_get_dom cannot pass arguments to file_get_contents #6

Closed
GoogleCodeExporter opened this issue Nov 22, 2015 · 2 comments
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

This issue was closed by revision r59.

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Thank you very much for reporting! I applied your fix.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant