Where is the problem with this simple code:
<?php
$dom = new DOMDocument();
@$dom->loadHTMLFile('https://www.google.com/search?q=newyork');
$xpath = new DOMXPath($dom);
$entries = $xpath->query("//h3/a/@href");
foreach($entries as $e) {
echo $e->textContent . '<br />';
}
?>
when I run I get only white window (nothing). Is problem with google?
Some advice, continuing on this related answer by Michael:
Try getting the HTML with
file_get_contents():If
file_get_contents()fails as well, make sureallow_url_fopenis enabled in your configuration (php.ini), or consider fetching the remote data using cURL.Anyway, with error reporting enabled PHP should show you some errors or warnings, which is always helpful when something doesn’t work as expected.