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" xmlns:x-trumba="http://schemas.trumba.com/rss/x-trumba"> <entry> <yt:duration seconds="105">test</yt:duration> <yt:duration seconds="1870">test</yt:duration> <x-trumba:customfield name="Event Type" id="21" type="number">Sound Publishing Event</x-trumba:customfield> <x-trumba:customfield name="Category" id="25674" type="text">Family</x-trumba:customfield> </entry> </feed>'; $xml = new SimpleXMLElement($buffer); foreach ($xml->entry as $item) { //original comment: how to get seconds? $namespaces = $item->getNameSpaces(true); $yt = $item->children($namespaces['yt']); $trumba = $item->children($namespaces['x-trumba']); $seconds = $yt->duration->attributes(); echo $seconds['seconds'], "\n"; // original comment: but doesn't work. $numofItems = $trumba->customfield->count(); foreach ($item->children('x-trumba', TRUE) as $child) { //echo $child->asXML(); //echo $child->attributes('id')); echo $child->attributes('x-trumba', TRUE)->Name; } foreach ($trumba->customfield as $custom) { $name = $trumba->customfield->attributes(); // var_dump($custom); } }
Output for git.master, git.master_jit, rfc.property-hooks
105

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:
59.65 ms | 401 KiB | 8 Q