I have a table such this :
<table>
<tr>
<td>Values</td>
<td>5000</td>
<td>6000</td>
</tr>
</table>
And I want to get td’s content. But I could not manage it.
<?PHP
$dom = new DOMDocument();
$dom->loadHTML("figures.html");
$table = $dom->getElementsByTagName('table');
$tds=$table->getElementsByTagName('td');
foreach ($tds as $t){
echo $t->nodeValue, "\n";
}
?>
There are multiple problems with this code:
DOMDocument::loadHTMLFile(), notloadHTML()as you have done. Use$dom->loadHTMLFile("figures.html").getElementsByTagName()on aDOMNodeListas you have done (on$table). It can only be used on aDOMDocument.You could do something like this:
Alternatively, you could just directly search for all elements with tag name
td(though I’m sure you want to do that in a table-specific manner.