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); $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 = 16, Position 2 = 37
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 37
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 28
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/g7Kgv
function name:  (null)
number of ops:  42
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        NEW                                              $12     'DOMXPath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $12
   10    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2F%2Fselect'
         13        DO_FCALL                                      0  $15     
         14        ASSIGN                                                   !3, $15
   11    15      > FE_RESET_R                                       $17     !3, ->37
         16    > > FE_FETCH_R                                               $17, !4, ->37
   12    17    >   INIT_METHOD_CALL                                         !2, 'query'
         18        SEND_VAL_EX                                              '%2F%2Foption'
         19        SEND_VAR_EX                                              !4
         20        DO_FCALL                                      0  $18     
         21        ASSIGN                                                   !5, $18
   13    22      > FE_RESET_R                                       $20     !5, ->28
         23    > > FE_FETCH_R                                               $20, !6, ->28
         24    >   INIT_METHOD_CALL                                         !6, 'removeAttribute'
         25        SEND_VAL_EX                                              'selected'
         26        DO_FCALL                                      0          
         27      > JMP                                                      ->23
         28    >   FE_FREE                                                  $20
   14    29        INIT_METHOD_CALL                                         !5, 'item'
         30        SEND_VAL_EX                                              1
         31        DO_FCALL                                      0  $22     
         32        INIT_METHOD_CALL                                         $22, 'setAttribute'
         33        SEND_VAL_EX                                              'selected'
         34        SEND_VAL_EX                                              'selected'
         35        DO_FCALL                                      0          
   11    36      > JMP                                                      ->16
         37    >   FE_FREE                                                  $17
   16    38        INIT_METHOD_CALL                                         !1, 'saveHTML'
         39        DO_FCALL                                      0  $24     
         40        ECHO                                                     $24
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.86 ms | 1399 KiB | 13 Q