3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * How to get attribute of node with namespace using SimpleXML? * * @link http://stackoverflow.com/q/6576773/367456 */ $buffer = '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <entry> <yt:duration seconds="1870"/> <yt:duration seconds="1875"/> </entry> </feed>'; $xml = new SimpleXMLElement($buffer); echo "ibxml version: ", LIBXML_DOTTED_VERSION, "\n"; foreach ($xml->entry as $item) { //original comment: how to get seconds? $namespaces = $item->getNameSpaces(true); $yt = $item->children($namespaces['yt']); var_dump($yt); $seconds = $yt->duration->attributes(); echo $seconds['seconds'], "\n"; // original comment: but doesn't work. } echo "done. should read 1870 one time.\n";
Output for git.master, git.master_jit, rfc.property-hooks
ibxml version: 2.9.4 object(SimpleXMLElement)#5 (1) { ["duration"]=> array(2) { [0]=> object(SimpleXMLElement)#7 (0) { } [1]=> object(SimpleXMLElement)#8 (0) { } } } 1870 done. should read 1870 one time.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
37.95 ms | 401 KiB | 8 Q