3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html =<<<EOF <form> <select><option>foo</option><option>bar</option></select> <select><option>hello</option><option>PHP</option></select> </form> EOF; $dom = new DOMDocument; $dom->loadHTML($html); $dom->formatOutput = true; $xpath = new DOMXPath($dom); $selects = $xpath->query('//select'); foreach ($selects as $select) { $options = $xpath->query('//option', $select); foreach ($options as $option) $option->removeAttribute('selected'); $options->item(1)->setAttribute('selected','selected'); } echo $dom->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 39
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 39
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 30
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/VQBjJ
function name:  (null)
number of ops:  44
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $selects, !4 = $select, !5 = $options, !6 = $option
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Cform%3E%0A++%3Cselect%3E%3Coption%3Efoo%3C%2Foption%3E%3Coption%3Ebar%3C%2Foption%3E%3C%2Fselect%3E%0A++%3Cselect%3E%3Coption%3Ehello%3C%2Foption%3E%3Coption%3EPHP%3C%2Foption%3E%3C%2Fselect%3E%0A%3C%2Fform%3E'
    8     1        NEW                                              $8      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $8
          4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
    9     7        ASSIGN_OBJ                                               !1, 'formatOutput'
          8        OP_DATA                                                  <true>
   10     9        NEW                                              $13     'DOMXPath'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $13
   11    13        INIT_METHOD_CALL                                         !2, 'query'
         14        SEND_VAL_EX                                              '%2F%2Fselect'
         15        DO_FCALL                                      0  $16     
         16        ASSIGN                                                   !3, $16
   12    17      > FE_RESET_R                                       $18     !3, ->39
         18    > > FE_FETCH_R                                               $18, !4, ->39
   13    19    >   INIT_METHOD_CALL                                         !2, 'query'
         20        SEND_VAL_EX                                              '%2F%2Foption'
         21        SEND_VAR_EX                                              !4
         22        DO_FCALL                                      0  $19     
         23        ASSIGN                                                   !5, $19
   14    24      > FE_RESET_R                                       $21     !5, ->30
         25    > > FE_FETCH_R                                               $21, !6, ->30
         26    >   INIT_METHOD_CALL                                         !6, 'removeAttribute'
         27        SEND_VAL_EX                                              'selected'
         28        DO_FCALL                                      0          
         29      > JMP                                                      ->25
         30    >   FE_FREE                                                  $21
   15    31        INIT_METHOD_CALL                                         !5, 'item'
         32        SEND_VAL_EX                                              1
         33        DO_FCALL                                      0  $23     
         34        INIT_METHOD_CALL                                         $23, 'setAttribute'
         35        SEND_VAL_EX                                              'selected'
         36        SEND_VAL_EX                                              'selected'
         37        DO_FCALL                                      0          
   12    38      > JMP                                                      ->18
         39    >   FE_FREE                                                  $18
   17    40        INIT_METHOD_CALL                                         !1, 'saveHTML'
         41        DO_FCALL                                      0  $25     
         42        ECHO                                                     $25
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.4 ms | 1390 KiB | 13 Q