3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<h2>Spiders</h2> <h2>Beetles</h2> <h3>External morphology</h3> <h4>Head</h4> <h4>Thorax</h4> <h4>Legs</h4> <h3>Anatomy and physiology</h3> <h2>Ants</h2>'; preg_match_all('/<h(\d)>([^<]+)/', $html, $matches); $cdepth = $matches[1][0] - 1; foreach ($matches[1] as $key => $depth) { if ($depth > $cdepth) { echo "\n" . str_repeat(' ', $cdepth * 4) . "<ol>\n"; } elseif ($depth < $cdepth) { echo "</li>\n" . str_repeat(' ', $depth * 4) . "</ol>\n" . str_repeat(' ', $depth * 4) . "</li>\n"; } else { echo "</li>\n"; } $cdepth = $depth; echo str_repeat(' ', $cdepth * 4) . "<li><a href=\"{$matches[2][$key]}\">{$matches[2][$key]}</a>"; } while ($cdepth-- >= $matches[1][0]) { echo "</li>\n" . str_repeat(' ', $cdepth * 4) . "</ol>\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 62
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 62
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 43
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 64
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 64
Branch analysis from position: 77
Branch analysis from position: 64
Branch analysis from position: 62
filename:       /in/FkXXE
function name:  (null)
number of ops:  78
compiled vars:  !0 = $html, !1 = $matches, !2 = $cdepth, !3 = $depth, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Ch2%3ESpiders%3C%2Fh2%3E%0A%3Ch2%3EBeetles%3C%2Fh2%3E%0A%3Ch3%3EExternal+morphology%3C%2Fh3%3E%0A%3Ch4%3EHead%3C%2Fh4%3E%0A%3Ch4%3EThorax%3C%2Fh4%3E%0A%3Ch4%3ELegs%3C%2Fh4%3E%0A%3Ch3%3EAnatomy+and+physiology%3C%2Fh3%3E%0A%3Ch2%3EAnts%3C%2Fh2%3E'
   12     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F%3Ch%28%5Cd%29%3E%28%5B%5E%3C%5D%2B%29%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   13     6        FETCH_DIM_R                                      ~7      !1, 1
          7        FETCH_DIM_R                                      ~8      ~7, 0
          8        SUB                                              ~9      ~8, 1
          9        ASSIGN                                                   !2, ~9
   14    10        FETCH_DIM_R                                      ~11     !1, 1
         11      > FE_RESET_R                                       $12     ~11, ->62
         12    > > FE_FETCH_R                                       ~13     $12, !3, ->62
         13    >   ASSIGN                                                   !4, ~13
   15    14        IS_SMALLER                                               !2, !3
         15      > JMPZ                                                     ~15, ->25
   16    16    >   INIT_FCALL                                               'str_repeat'
         17        SEND_VAL                                                 '+'
         18        MUL                                              ~16     !2, 4
         19        SEND_VAL                                                 ~16
         20        DO_ICALL                                         $17     
         21        CONCAT                                           ~18     '%0A', $17
         22        CONCAT                                           ~19     ~18, '%3Col%3E%0A'
         23        ECHO                                                     ~19
   15    24      > JMP                                                      ->44
   18    25    >   IS_SMALLER                                               !3, !2
         26      > JMPZ                                                     ~20, ->43
   19    27    >   INIT_FCALL                                               'str_repeat'
         28        SEND_VAL                                                 '+'
         29        MUL                                              ~21     !3, 4
         30        SEND_VAL                                                 ~21
         31        DO_ICALL                                         $22     
         32        CONCAT                                           ~23     '%3C%2Fli%3E%0A', $22
         33        CONCAT                                           ~24     ~23, '%3C%2Fol%3E%0A'
         34        INIT_FCALL                                               'str_repeat'
         35        SEND_VAL                                                 '+'
         36        MUL                                              ~25     !3, 4
         37        SEND_VAL                                                 ~25
         38        DO_ICALL                                         $26     
         39        CONCAT                                           ~27     ~24, $26
         40        CONCAT                                           ~28     ~27, '%3C%2Fli%3E%0A'
         41        ECHO                                                     ~28
   18    42      > JMP                                                      ->44
   22    43    >   ECHO                                                     '%3C%2Fli%3E%0A'
   24    44    >   ASSIGN                                                   !2, !3
   25    45        INIT_FCALL                                               'str_repeat'
         46        SEND_VAL                                                 '+'
         47        MUL                                              ~30     !2, 4
         48        SEND_VAL                                                 ~30
         49        DO_ICALL                                         $31     
         50        ROPE_INIT                                     5  ~37     '%3Cli%3E%3Ca+href%3D%22'
         51        FETCH_DIM_R                                      ~32     !1, 2
         52        FETCH_DIM_R                                      ~33     ~32, !4
         53        ROPE_ADD                                      1  ~37     ~37, ~33
         54        ROPE_ADD                                      2  ~37     ~37, '%22%3E'
         55        FETCH_DIM_R                                      ~34     !1, 2
         56        FETCH_DIM_R                                      ~35     ~34, !4
         57        ROPE_ADD                                      3  ~37     ~37, ~35
         58        ROPE_END                                      4  ~36     ~37, '%3C%2Fa%3E'
         59        CONCAT                                           ~40     $31, ~36
         60        ECHO                                                     ~40
   14    61      > JMP                                                      ->12
         62    >   FE_FREE                                                  $12
   27    63      > JMP                                                      ->72
   28    64    >   INIT_FCALL                                               'str_repeat'
         65        SEND_VAL                                                 '+'
         66        MUL                                              ~41     !2, 4
         67        SEND_VAL                                                 ~41
         68        DO_ICALL                                         $42     
         69        CONCAT                                           ~43     '%3C%2Fli%3E%0A', $42
         70        CONCAT                                           ~44     ~43, '%3C%2Fol%3E%0A'
         71        ECHO                                                     ~44
   27    72    >   POST_DEC                                         ~45     !2
         73        FETCH_DIM_R                                      ~46     !1, 1
         74        FETCH_DIM_R                                      ~47     ~46, 0
         75        IS_SMALLER_OR_EQUAL                                      ~47, ~45
         76      > JMPNZ                                                    ~48, ->64
   29    77    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.53 ms | 1020 KiB | 15 Q