PHP how to count xml elements in object returned by simplexml_load_file(),
<p>I have inherited some PHP code (but I've little PHP experience) and can't find how to count some elements in the object returned by <code>simplexml_load_file()</code></p>

<p>The code is something like this</p>

<pre><code>$xml = simplexml_load_file($feed);
for ($x=0; $x&lt;6; $x++) {
   $title = $xml-&gt;channel[0]-&gt;item[$x]-&gt;title[0];
   echo "&lt;li&gt;" . $title . "&lt;/li&gt;\n";
} 
</code></pre>

<p>It assumes there will be at least 6 <code>&lt;item&gt;</code> elements but sometimes there are fewer so I get warning messages in the output on my development system (though not on live).</p>

<p>How do I extract a count of <code>&lt;item&gt;</code> elements in <code>$xml-&gt;channel[0]</code>?</p>
