3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * How to get attribute of node with namespace using SimpleXML? * * @link http://stackoverflow.com/q/6576773/367456 */ $buffer = '<ns:feed xmlns:ns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <ns:entry> <yt:duration seconds="1870"/> </ns:entry> </ns: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']); $seconds = $yt->duration->attributes(); echo $seconds['seconds'], "\n"; // original comment: but doesn't work. } echo "done. should read 1870 one time.\n";
based on qY70Y
Output for 5.6.30, 7.0.30 - 7.3.0alpha1
ibxml version: 2.9.4 done. should read 1870 one time.
Output for hhvm-3.18.5 - 3.22.0
ibxml version: 2.9.1 done. should read 1870 one time.