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); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 59
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 59
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 48
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 48
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 48
2 jumps found. (Code = 77) Position 1 = 51, Position 2 = 57
Branch analysis from position: 51
2 jumps found. (Code = 78) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 57
Branch analysis from position: 48
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
filename:       /in/N7jdJ
function name:  (null)
number of ops:  61
compiled vars:  !0 = $buffer, !1 = $xml, !2 = $item, !3 = $namespaces, !4 = $yt, !5 = $trumba, !6 = $seconds, !7 = $numofItems, !8 = $child, !9 = $custom, !10 = $name
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+xmlns%3Ax-trumba%3D%22http%3A%2F%2Fschemas.trumba.com%2Frss%2Fx-trumba%22%3E%0A++++%3Centry%3E%0A++++++++%3Cyt%3Aduration+seconds%3D%22105%22%3Etest%3C%2Fyt%3Aduration%3E%0A++++++++%3Cyt%3Aduration+seconds%3D%221870%22%3Etest%3C%2Fyt%3Aduration%3E%0A++++++++%3Cx-trumba%3Acustomfield+name%3D%22Event+Type%22+id%3D%2221%22+type%3D%22number%22%3ESound+Publishing+Event%3C%2Fx-trumba%3Acustomfield%3E%0A++++++++%3Cx-trumba%3Acustomfield+name%3D%22Category%22+id%3D%2225674%22+type%3D%22text%22%3EFamily%3C%2Fx-trumba%3Acustomfield%3E%0A++++%3C%2Fentry%3E%0A%3C%2Ffeed%3E'
   16     1        NEW                                              $12     'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $12
   19     5        FETCH_OBJ_R                                      ~15     !1, 'entry'
          6      > FE_RESET_R                                       $16     ~15, ->59
          7    > > FE_FETCH_R                                               $16, !2, ->59
   22     8    >   INIT_METHOD_CALL                                         !2, 'getNameSpaces'
          9        SEND_VAL_EX                                              <true>
         10        DO_FCALL                                      0  $17     
         11        ASSIGN                                                   !3, $17
   23    12        INIT_METHOD_CALL                                         !2, 'children'
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $19     !3, 'yt'
         15        SEND_FUNC_ARG                                            $19
         16        DO_FCALL                                      0  $20     
         17        ASSIGN                                                   !4, $20
   24    18        INIT_METHOD_CALL                                         !2, 'children'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $22     !3, 'x-trumba'
         21        SEND_FUNC_ARG                                            $22
         22        DO_FCALL                                      0  $23     
         23        ASSIGN                                                   !5, $23
   25    24        FETCH_OBJ_R                                      ~25     !4, 'duration'
         25        INIT_METHOD_CALL                                         ~25, 'attributes'
         26        DO_FCALL                                      0  $26     
         27        ASSIGN                                                   !6, $26
   26    28        FETCH_DIM_R                                      ~28     !6, 'seconds'
         29        ECHO                                                     ~28
         30        ECHO                                                     '%0A'
   27    31        FETCH_OBJ_R                                      ~29     !5, 'customfield'
         32        INIT_METHOD_CALL                                         ~29, 'count'
         33        DO_FCALL                                      0  $30     
         34        ASSIGN                                                   !7, $30
   28    35        INIT_METHOD_CALL                                         !2, 'children'
         36        SEND_VAL_EX                                              'x-trumba'
         37        SEND_VAL_EX                                              <true>
         38        DO_FCALL                                      0  $32     
         39      > FE_RESET_R                                       $33     $32, ->48
         40    > > FE_FETCH_R                                               $33, !8, ->48
   31    41    >   INIT_METHOD_CALL                                         !8, 'attributes'
         42        SEND_VAL_EX                                              'x-trumba'
         43        SEND_VAL_EX                                              <true>
         44        DO_FCALL                                      0  $34     
         45        FETCH_OBJ_R                                      ~35     $34, 'Name'
         46        ECHO                                                     ~35
   28    47      > JMP                                                      ->40
         48    >   FE_FREE                                                  $33
   35    49        FETCH_OBJ_R                                      ~36     !5, 'customfield'
         50      > FE_RESET_R                                       $37     ~36, ->57
         51    > > FE_FETCH_R                                               $37, !9, ->57
   36    52    >   FETCH_OBJ_R                                      ~38     !5, 'customfield'
         53        INIT_METHOD_CALL                                         ~38, 'attributes'
         54        DO_FCALL                                      0  $39     
         55        ASSIGN                                                   !10, $39
   35    56      > JMP                                                      ->51
         57    >   FE_FREE                                                  $37
   19    58      > JMP                                                      ->7
         59    >   FE_FREE                                                  $16
   40    60      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.21 ms | 1399 KiB | 13 Q