I loaded an XML file using simpelxml. Is there a way to count how many entries there are in that file? //my xml file <pets> <breed>Bulldog</breed> <breed>Terrier</breed> <breed>Chihuahua</breed> </pets> Code (markup): How do I get the number of entries in my XML file which in this case is 3? I hope to add more entries as the days go by.
Try this <? $xml= "abc.xml"; //your xml filename $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $product = $xmlDoc->getElementsByTagName("breed"); $numOfproducts = $product->length; echo $numOfproducts; ?> Regards Alex
if you only want to use simplexml: $c=0; foreach($xml->breed as $b) $c++; PHP: which returns $c=3 or $c = count($xml->breed); PHP: which is zero-based and returns $c=2