I want to get the values inside tds. I can do it by getElementsByTagName but I could not manage it by using getElementById.
The HTML might look like this:
<table id="myid">
<tr>
<td>value1</td>
<td>value2</td>
</tr>
<tr>
<td>value1</td>
<td>value2</td>
</tr>
</table>
The php used to access the values is:
<?PHP
$dom = new DOMDocument();
$dom->loadHTMLfile('http://remoteDomain/thispage.html');
$table=$dom->getElementById('myid');
foreach($table->getElementsByTagName('tr') as $key =>$tr){
$tr->getElementsByTagName('td')->item(0)->nodeValue;
}
?>
EDIT
I got the error:
Fatal error: Call to a member function getElementsByTagName() on a non-object in …
EDIT2
Php info:
DOM/XML enabled
DOM/XML API Version 20031129
libxml Version 2.7.3
Operating system: Windows
As I understand, you want to use in foreach getElementById, and your code is working.
As it could be seen there is difference in the name
getElement[S]ByTagNameandgetElementById, with purpose.The definition of id is so to say to be unique identifier of element in a page, so only one id (unique) value is assumed to persist on single page and this value cannot be assigned to another element id. If you have more than one element with the same id value, it is wrong (since HTML 4 or XHTML 1.0, I think).
The way you use, looks valid.
EDIT
In this case you may have an anwser here: Same problem already solved