lundi 1 décembre 2014

PHP DOMDocument and getElementsByTagName questions?


Vote count:

0




I am trying read the h1 value from HTML string like below,



<h1>
<a href="http://ift.tt/1veLtRZ"> love me for a reason </a>
</h1>


I am using the following code but this returns empty value for the title but the content seems to working (next line) ? why



libxml_use_internal_errors(true);
$dom_document = new DOMDocument(); // CREATE A NEW DOCUMENT
$dom_document->loadHTML(mb_convert_encoding($row['html'], 'HTML-ENTITIES', 'UTF-8')); // LOAD THE STRING INTO THE DOCUMENT

$article_titles=$dom_document->getElementsByTagName("h1");
$title = $article_titles->textContent;


//this works fine
$article_contents=$dom_document->getElementByID("article-single");
$content=$article_contents->textContent;
libxml_use_internal_errors(false);


asked 56 secs ago







PHP DOMDocument and getElementsByTagName questions?

Aucun commentaire:

Enregistrer un commentaire