Hello guys I want to get an HTML node from website to show it in my website, but I can't do it.
This is my code.
$html = htmlentities(file_get_contents("http://stackoverflow.com/"));
$doc = new DOMDocument();
$doc->loadHTML($html);
$h1 = $doc->getElementsByTagName("title");
var_dump($h1);
And this is the result.
object(DOMNodeList)#2 (1) {
["length"]=>
int(0)
}
Please help. Thanks in advance.
htmlentities.DOMDocumentexpects you to load the original HTML, not the HTML converted to entities.$doc = new DOMDocument(); $doc->loadHTML("http://stackoverflow.com/"); $h1 = $doc->getElementsByTagName("title")->item(0)->textContent; print_r($h1);gives me Null.