3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo '<pre>'; $html = " <p>consectetur <b>adipisc<i>in</i>g </b>elit. Maecenas sit amet molestie enim. Nulla gravida mi sed ipsum </p> <p>pellentesque<br>ut pulvinar orci consequat. Donec tempus rutrum urna at iaculis. Ut sagittis, tellus eu venenatis imperdiet,</p> <ol> <li> <ol> <li><b></b></li> <li>sdaf</li> </ol> sem dolor mattis leo, </li> <li>in consequat elit lorem ut ligula.</li> </ol> Praessadf"; echo $html."<br>"; var_dump(check_html($html)); function check_html($html) { $tags = array(); preg_match_all('#<(/?[a-zA-Z]+)\b.*?>#im', $html, $tags); $tags = array_map('strtolower', $tags[1]); $lists = array('ul', 'ol'); $single_tags = array('br'); $tags_stack = new SplStack(); $lists_stack = new SplStack(); foreach ($tags as $tag) { if ($tag[0] != '/') { // start tag if (in_array($tag, $single_tags)) { // if single tag, just continue continue; } elseif (in_array($tag, $lists)) { $lists_stack->push($tag); // new list starts } $tags_stack->push($tag); } else { // end tag if (!$tags_stack->count()) { return false; // there aren't opened tags } $end_tag = trim($tag, '/'); // handle lists if (in_array($end_tag, $lists)) { if (!$lists_stack->count() || $lists_stack->pop() != $end_tag) { return false; // there are no opened lists or unclosed list tag } } elseif ($end_tag == 'li') { if (!$lists_stack->count()) { return false; // there are no opened lists } } if ($tags_stack->pop() != $end_tag) { return false; // unclosed tag } } } return !$tags_stack->count(); // true if stack is empty }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RkfLB
function name:  (null)
number of ops:  11
compiled vars:  !0 = $html
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ECHO                                                     '%3Cpre%3E'
    3     1        ASSIGN                                                   !0, '%0A%3Cp%3Econsectetur+%3Cb%3Eadipisc%3Ci%3Ein%3C%2Fi%3Eg+%3C%2Fb%3Eelit.+Maecenas+sit+amet+molestie+enim.+Nulla+gravida+mi+sed+ipsum+%3C%2Fp%3E+%0A%3Cp%3Epellentesque%3Cbr%3Eut+pulvinar+orci+consequat.+Donec+tempus+rutrum+urna+at+iaculis.+Ut+sagittis%2C+tellus+eu+venenatis+imperdiet%2C%3C%2Fp%3E+%0A%0A%3Col%3E+%0A%3Cli%3E%0A++%3Col%3E%0A++++%3Cli%3E%3Cb%3E%3C%2Fb%3E%3C%2Fli%3E%0A++++%3Cli%3Esdaf%3C%2Fli%3E+%0A++%3C%2Fol%3E+%0Asem+dolor+mattis+leo%2C+%0A%0A%3C%2Fli%3E++%0A%3Cli%3Ein+consequat+elit+lorem+ut+ligula.%3C%2Fli%3E+%0A%3C%2Fol%3E+%0APraessadf'
   20     2        CONCAT                                           ~2      !0, '%3Cbr%3E'
          3        ECHO                                                     ~2
   22     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL_BY_NAME                                       'check_html'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                                 
   72    10      > RETURN                                                   1

Function check_html:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 88
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 88
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 45
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 41
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 73
Branch analysis from position: 61
2 jumps found. (Code = 47) Position 1 = 65, Position 2 = 69
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 72
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 81
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 87
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 87
Branch analysis from position: 69
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 81
Branch analysis from position: 75
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 81
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 81
Branch analysis from position: 81
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 88
filename:       /in/RkfLB
function name:  check_html
number of ops:  94
compiled vars:  !0 = $html, !1 = $tags, !2 = $lists, !3 = $single_tags, !4 = $tags_stack, !5 = $lists_stack, !6 = $tag, !7 = $end_tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ASSIGN                                                   !1, <array>
   26     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAL                                                 '%23%3C%28%2F%3F%5Ba-zA-Z%5D%2B%29%5Cb.%2A%3F%3E%23im'
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !1
          6        DO_ICALL                                                 
   27     7        INIT_FCALL                                               'array_map'
          8        SEND_VAL                                                 'strtolower'
          9        FETCH_DIM_R                                      ~10     !1, 1
         10        SEND_VAL                                                 ~10
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !1, $11
   29    13        ASSIGN                                                   !2, <array>
   30    14        ASSIGN                                                   !3, <array>
   32    15        NEW                                              $15     'SplStack'
         16        DO_FCALL                                      0          
         17        ASSIGN                                                   !4, $15
   33    18        NEW                                              $18     'SplStack'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !5, $18
   35    21      > FE_RESET_R                                       $21     !1, ->88
         22    > > FE_FETCH_R                                               $21, !6, ->88
   37    23    >   FETCH_DIM_R                                      ~22     !6, 0
         24        IS_NOT_EQUAL                                             ~22, '%2F'
         25      > JMPZ                                                     ~23, ->45
   39    26    >   INIT_FCALL                                               'in_array'
         27        SEND_VAR                                                 !6
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $24     
         30      > JMPZ                                                     $24, ->33
   40    31    > > JMP                                                      ->22
         32*       JMP                                                      ->41
   41    33    >   INIT_FCALL                                               'in_array'
         34        SEND_VAR                                                 !6
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                         $25     
         37      > JMPZ                                                     $25, ->41
   42    38    >   INIT_METHOD_CALL                                         !5, 'push'
         39        SEND_VAR_EX                                              !6
         40        DO_FCALL                                      0          
   44    41    >   INIT_METHOD_CALL                                         !4, 'push'
         42        SEND_VAR_EX                                              !6
         43        DO_FCALL                                      0          
         44      > JMP                                                      ->87
   48    45    >   INIT_METHOD_CALL                                         !4, 'count'
         46        DO_FCALL                                      0  $28     
         47        BOOL_NOT                                         ~29     $28
         48      > JMPZ                                                     ~29, ->51
   49    49    >   FE_FREE                                                  $21
         50      > RETURN                                                   <false>
   52    51    >   INIT_FCALL                                               'trim'
         52        SEND_VAR                                                 !6
         53        SEND_VAL                                                 '%2F'
         54        DO_ICALL                                         $30     
         55        ASSIGN                                                   !7, $30
   55    56        INIT_FCALL                                               'in_array'
         57        SEND_VAR                                                 !7
         58        SEND_VAR                                                 !2
         59        DO_ICALL                                         $32     
         60      > JMPZ                                                     $32, ->73
   56    61    >   INIT_METHOD_CALL                                         !5, 'count'
         62        DO_FCALL                                      0  $33     
         63        BOOL_NOT                                         ~34     $33
         64      > JMPNZ_EX                                         ~34     ~34, ->69
         65    >   INIT_METHOD_CALL                                         !5, 'pop'
         66        DO_FCALL                                      0  $35     
         67        IS_NOT_EQUAL                                     ~36     !7, $35
         68        BOOL                                             ~34     ~36
         69    > > JMPZ                                                     ~34, ->72
   57    70    >   FE_FREE                                                  $21
         71      > RETURN                                                   <false>
         72    > > JMP                                                      ->81
   59    73    >   IS_EQUAL                                                 !7, 'li'
         74      > JMPZ                                                     ~37, ->81
   60    75    >   INIT_METHOD_CALL                                         !5, 'count'
         76        DO_FCALL                                      0  $38     
         77        BOOL_NOT                                         ~39     $38
         78      > JMPZ                                                     ~39, ->81
   61    79    >   FE_FREE                                                  $21
         80      > RETURN                                                   <false>
   65    81    >   INIT_METHOD_CALL                                         !4, 'pop'
         82        DO_FCALL                                      0  $40     
         83        IS_NOT_EQUAL                                             !7, $40
         84      > JMPZ                                                     ~41, ->87
   66    85    >   FE_FREE                                                  $21
         86      > RETURN                                                   <false>
   35    87    > > JMP                                                      ->22
         88    >   FE_FREE                                                  $21
   71    89        INIT_METHOD_CALL                                         !4, 'count'
         90        DO_FCALL                                      0  $42     
         91        BOOL_NOT                                         ~43     $42
         92      > RETURN                                                   ~43
   72    93*     > RETURN                                                   null

End of function check_html

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.91 ms | 1404 KiB | 23 Q