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"/> </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']); $seconds = $yt->duration->attributes(); echo $seconds['seconds']; // original comment: but doesn't work. }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/M3qf2
function name:  (null)
number of ops:  27
compiled vars:  !0 = $buffer, !1 = $xml, !2 = $item, !3 = $namespaces, !4 = $yt, !5 = $seconds
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, '%3Cfeed+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2005%2FAtom%22+xmlns%3Ayt%3D%22http%3A%2F%2Fgdata.youtube.com%2Fschemas%2F2007%22%3E%0A++++%3Centry%3E%0A++++++++%3Cyt%3Aduration+seconds%3D%221870%22%2F%3E%0A++++%3C%2Fentry%3E%0A%3C%2Ffeed%3E'
   13     1        NEW                                              $7      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $7
   15     5        FETCH_OBJ_R                                      ~10     !1, 'entry'
          6      > FE_RESET_R                                       $11     ~10, ->25
          7    > > FE_FETCH_R                                               $11, !2, ->25
   18     8    >   INIT_METHOD_CALL                                         !2, 'getNameSpaces'
          9        SEND_VAL_EX                                              <true>
         10        DO_FCALL                                      0  $12     
         11        ASSIGN                                                   !3, $12
   19    12        INIT_METHOD_CALL                                         !2, 'children'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $14     !3, 'yt'
         15        SEND_FUNC_ARG                                            $14
         16        DO_FCALL                                      0  $15     
         17        ASSIGN                                                   !4, $15
   20    18        FETCH_OBJ_R                                      ~17     !4, 'duration'
         19        INIT_METHOD_CALL                                         ~17, 'attributes'
         20        DO_FCALL                                      0  $18     
         21        ASSIGN                                                   !5, $18
   22    22        FETCH_DIM_R                                      ~20     !5, 'seconds'
         23        ECHO                                                     ~20
   15    24      > JMP                                                      ->7
         25    >   FE_FREE                                                  $11
   23    26      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
193.03 ms | 1395 KiB | 13 Q