note 98443 added to simplexmlelement.count

From: Date: Wed, 16 Jun 2010 01:33:55 +0000
Subject: note 98443 added to simplexmlelement.count
Groups: php.notes 
Request: Send a blank email to php-notes+get-170161@lists.php.net to get a copy of this message
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. $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 />"; ---- Server IP: 69.147.83.197 Probable Submitter: 99.156.151.35 ---- Manual Page -- http://www.php.net/manual/en/simplexmlelement.count.php Edit -- https://master.php.net/note/edit/98443 Del: integrated -- https://master.php.net/note/delete/98443/integrated Del: useless -- https://master.php.net/note/delete/98443/useless Del: bad code -- https://master.php.net/note/delete/98443/bad+code Del: spam -- https://master.php.net/note/delete/98443/spam Del: non-english -- https://master.php.net/note/delete/98443/non-english Del: in docs -- https://master.php.net/note/delete/98443/in+docs Del: other reasons-- https://master.php.net/note/delete/98443 Reject -- https://master.php.net/note/reject/98443 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170161) next »