Getting element length with php DOM
<p>I'm stuck with this.
I try to use php dom to parse some html code.
How can I get to know how many children current element has witch I iterate through in for loop?</p>

<pre><code>&lt;?php
$str='
&lt;table id="tableId"&gt;
&lt;tr&gt;
    &lt;td&gt;row1 cell1&lt;/td&gt;
    &lt;td&gt;row1 cell2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;row2 cell1&lt;/td&gt;
    &lt;td&gt;row2 cell2&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
';

$DOM = new DOMDocument;
$DOM-&gt;loadHTML($str);   // loading page contents
$table = $DOM-&gt;getElementById('tableId');   // getting the table that I need
$DOM-&gt;loadHTML($table);     

$tr = $DOM-&gt;getElementsByTagName('tr');     // getting rows

echo $tr-&gt;item(0)-&gt;nodeValue;   // outputs row1 cell1 row1 cell2 - exactly as I expect with both rows
echo "&lt;br&gt;";
echo $tr-&gt;item(1)-&gt;nodeValue;   // outputs row2 cell1 row2 cell2

// now I need to iterate through each row to build an array with cells that it has
for ($i = 0; $i &lt; $tr-&gt;length; $i++)
{
echo $tr-&gt;item($i)-&gt;length;     // outputs no value. But how can I get it?
echo $i."&lt;br /&gt;";
}
?&gt;
</code></pre>
