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:seconds="0 in yt namespace" /> </entry> </feed>'; $xml = new SimpleXMLElement($buffer); if (!defined('LIBXML_DOTTED_VERSION')) { echo "PHP/LIBXML unsupported/too old."; return; } echo "ibxml version: ", LIBXML_DOTTED_VERSION, "\n"; $youtube = $xml; echo 'via attributes(): ', $youtube->entry->children('yt', TRUE)->duration->attributes()->seconds, "\n"; echo 'via array-access: ', $youtube->entry->children('yt', TRUE)->duration['seconds'], "\n"; echo 'via property : ', $youtube->entry->children('yt', TRUE)->duration->seconds, "\n";
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
ibxml version: 2.9.4 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.3.25 - 5.3.29
ibxml version: 2.9.1 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.3.15 - 5.3.24
ibxml version: 2.8.0 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.3.0 - 5.3.14
ibxml version: 2.7.8 via attributes(): 1870 via array-access: 0 in yt namespace via property :

preferences:
63.45 ms | 409 KiB | 5 Q