3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html1 = <<<EOT <option selected="selected" value="1">value text</option> EOT; $html2 = <<<EOT <option selected value="1">value text</option> EOT; $html3 = <<<EOT <option value="the devil with **selected** ">value text</option> EOT; function get_selected($html) { $doc = new DOMDocument; $doc->loadHTML($html); $xpath = new DOMXpath($regex); foreach ($xpath->query("//option") as $option) { $selected_value = $xpath->evaluate('string(@value)', $option); return $selected_value; } } var_dump( get_selected($html1) ); var_dump( get_selected($html2) ); var_dump( get_selected($html3) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/betQW
function name:  (null)
number of ops:  22
compiled vars:  !0 = $html1, !1 = $html2, !2 = $html3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Coption+selected%3D%22selected%22+value%3D%221%22%3Evalue+text%3C%2Foption%3E'
    6     1        ASSIGN                                                   !1, '%3Coption+selected+value%3D%221%22%3Evalue+text%3C%2Foption%3E'
    9     2        ASSIGN                                                   !2, '%3Coption+value%3D%22the+devil+with+%2A%2Aselected%2A%2A+%22%3Evalue+text%3C%2Foption%3E'
   24     3        INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'get_selected'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $6      
          7        SEND_VAR                                                 $6
          8        DO_ICALL                                                 
   25     9        INIT_FCALL                                               'var_dump'
         10        INIT_FCALL                                               'get_selected'
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $8      
         13        SEND_VAR                                                 $8
         14        DO_ICALL                                                 
   26    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'get_selected'
         17        SEND_VAR                                                 !2
         18        DO_FCALL                                      0  $10     
         19        SEND_VAR                                                 $10
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function get_selected:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/betQW
function name:  get_selected
number of ops:  26
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $regex, !4 = $option, !5 = $selected_value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
   16     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   17     7        NEW                                              $10     'DOMXpath'
          8        SEND_VAR_EX                                              !3
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $10
   18    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2F%2Foption'
         13        DO_FCALL                                      0  $13     
         14      > FE_RESET_R                                       $14     $13, ->24
         15    > > FE_FETCH_R                                               $14, !4, ->24
   19    16    >   INIT_METHOD_CALL                                         !2, 'evaluate'
         17        SEND_VAL_EX                                              'string%28%40value%29'
         18        SEND_VAR_EX                                              !4
         19        DO_FCALL                                      0  $15     
         20        ASSIGN                                                   !5, $15
   20    21        FE_FREE                                                  $14
         22      > RETURN                                                   !5
   18    23*       JMP                                                      ->15
         24    >   FE_FREE                                                  $14
   22    25      > RETURN                                                   null

End of function get_selected

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.62 ms | 1403 KiB | 18 Q