3v4l.org

run code in 300+ PHP versions simultaneously
<?php $output = '<results> <error> <string>i</string> <description>Make I uppercase</description> <precontext></precontext> <suggestions> <option>I</option> </suggestions> <type>grammar</type> </error> </results>'; $dom = new DOMDocument(); $dom->loadXml($output); $params = $dom->getElementsByTagName('error'); // Find Sections $k=0; foreach ($params as $param) //go to each section 1 by 1 { if ($param->getElementsByTagName('type')->length && $param->getElementsByTagName('type')[0]->nodeValue === 'grammar') { echo $param->getElementsByTagName('description')[0]->nodeValue; }else{ echo "other type"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 36
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 36
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 26
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/iNj0M
function name:  (null)
number of ops:  38
compiled vars:  !0 = $output, !1 = $dom, !2 = $params, !3 = $k, !4 = $param
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cresults%3E%0A++%3Cerror%3E%0A++++%3Cstring%3Ei%3C%2Fstring%3E%0A++++%3Cdescription%3EMake+I+uppercase%3C%2Fdescription%3E%0A++++%3Cprecontext%3E%3C%2Fprecontext%3E%0A++++%3Csuggestions%3E%0A++++++++%3Coption%3EI%3C%2Foption%3E%0A++++%3C%2Fsuggestions%3E%0A++++%3Ctype%3Egrammar%3C%2Ftype%3E++++%0A++%3C%2Ferror%3E%0A%3C%2Fresults%3E'
   15     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   16     4        INIT_METHOD_CALL                                         !1, 'loadXml'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   17     7        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
          8        SEND_VAL_EX                                              'error'
          9        DO_FCALL                                      0  $10     
         10        ASSIGN                                                   !2, $10
   18    11        ASSIGN                                                   !3, 0
   19    12      > FE_RESET_R                                       $13     !2, ->36
         13    > > FE_FETCH_R                                               $13, !4, ->36
   21    14    >   INIT_METHOD_CALL                                         !4, 'getElementsByTagName'
         15        SEND_VAL_EX                                              'type'
         16        DO_FCALL                                      0  $14     
         17        FETCH_OBJ_R                                      ~15     $14, 'length'
         18      > JMPZ_EX                                          ~15     ~15, ->26
         19    >   INIT_METHOD_CALL                                         !4, 'getElementsByTagName'
         20        SEND_VAL_EX                                              'type'
         21        DO_FCALL                                      0  $16     
         22        FETCH_DIM_R                                      ~17     $16, 0
         23        FETCH_OBJ_R                                      ~18     ~17, 'nodeValue'
         24        IS_IDENTICAL                                     ~19     ~18, 'grammar'
         25        BOOL                                             ~15     ~19
         26    > > JMPZ                                                     ~15, ->34
   22    27    >   INIT_METHOD_CALL                                         !4, 'getElementsByTagName'
         28        SEND_VAL_EX                                              'description'
         29        DO_FCALL                                      0  $20     
         30        FETCH_DIM_R                                      ~21     $20, 0
         31        FETCH_OBJ_R                                      ~22     ~21, 'nodeValue'
         32        ECHO                                                     ~22
   21    33      > JMP                                                      ->35
   24    34    >   ECHO                                                     'other+type'
   19    35    > > JMP                                                      ->13
         36    >   FE_FREE                                                  $13
   26    37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.23 ms | 1000 KiB | 13 Q