PHP getElementByTagName nodeValue return nothing

Tuesday, July 1, 2014


//example page
<h1 id="t">Hello You</h1>


//CURL
$url = 'http://www.example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$site = curl_exec($ch);

//DOM
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($site);



$byId = $dom->getElementById('t');
$byName = $dom->getElementsByTagName('h1');

echo $byId->nodeValue;
echo $byName->nodeValue;


I have a page I try to get nodeValue


When I use getElementById, I got the value, but If I tried byTagName, it return nothing.







http://ift.tt/Vb3pOx