I’m digging a solution for the last 5 hours and I can’t believe that i’m asking my first question here for such a simple problem, so the code is:
$urlContents = file_get_contents('http://www.google.com');
$dom = new DOMDocument();
$contents = $dom->loadHTMLFile($urlContents); //$contents = 'source code from www-google.com'
$divsInDomDoc = $dom->getElementsByTagName('div'); // $divsInDomDoc becames a DomNodeList with length = 0
$nNodes = $divsInDomDoc->length // using this to check length
Please somebody help!
In addition to Tim Cooper’s change, you also need to use
loadHTML()instead ofloadHTMLFile(), since you already have the contents of the site in a string.loadHTMLFile()is for reading a file.