note 98443 deleted from simplexmlelement.count by danbrown

From: Date: Fri, 25 Jun 2010 15:26:11 +0000
Subject: note 98443 deleted from simplexmlelement.count by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170462@lists.php.net to get a copy of this message
Note Submitter: Jimmy New Tron ---- I used the DOMNodeList $length property to simulate this function since my host had not yet implemented PHP 5.3. The following code makes it portable and allows you to prepare for an upgrade path. <?php $url = "http://www.example.com/foo.xml"; $xml = simplexml_load_file($url); // For debugging // echo "<p>".phpversion()."</p>"; if(phpversion() >= '5.3.0'){ $bar_count = $xml->foo->bar->count(); } else { $doc = new DOMDocument(); $str = $xml->asXML(); $doc->loadXML($str); $bar_count = $doc->getElementsByTagName("bar")->length; } echo "There are ".$bar_count." \"bar\" nodes in this document.<br />"; ?>

« previous php.notes (#170462) next »