3v4l.org

run code in 300+ PHP versions simultaneously
<?php $offsets = [ 1 => [0,2], 2 => [2,5], 3 => [8,9] ]; $html = <<<HTML <div>This is</div> only a test for stackoverflow HTML; $ignoreTag = false; $insertTagStart = false; $char = 0; for ($i = 0; $i < strlen($html); ++$i) { if ($ignoreTag && $html[$i] == '>') { $ignoreTag = false; } elseif ($html[$i] == '<') { if ($insertTagStart !== false) { // insert tag interruption, print closing tag, modify the lookup ++$offsets[$insertTagStart][0]; $html = substr_replace($html, "</span>", $i, 0); $i += 6; // </span> = 7 minus 1 before loop's increment } $ignoreTag = true; } else { foreach ($offsets as $id => $set) { if ($char == $set[0]) { $insertTagStart = $id; $insertTag = "<span class='annotation n-{$id}'>"; $i += strlen($insertTag) - 1; // compensate for inserted substring while traversing html $html = substr_replace($html, $insertTag, $char, 0); } elseif ($insertTagStart == $id && $set[1] == $char) { $html = substr_replace($html, "</span>", $char, 0); $insertTagStart = false; } } ++$char; } echo "{$char},\t" , ($ignoreTag ? 't' : 'f') , ",\t" , ($insertTagStart === false ? 'f' : $insertTagStart) , ",\t" , $html , "\n"; } echo $html;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 7
Branch analysis from position: 93
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 77
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 7
Branch analysis from position: 93
Branch analysis from position: 7
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 7
Branch analysis from position: 93
Branch analysis from position: 7
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 84
Branch analysis from position: 82
Branch analysis from position: 84
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 32
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 30
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 30
Branch analysis from position: 32
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 69
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 69
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 54
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 54
2 jumps found. (Code = 46) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 68
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 68
Branch analysis from position: 59
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 77
Branch analysis from position: 75
Branch analysis from position: 77
Branch analysis from position: 69
Branch analysis from position: 11
filename:       /in/IvgBT
function name:  (null)
number of ops:  95
compiled vars:  !0 = $offsets, !1 = $html, !2 = $ignoreTag, !3 = $insertTagStart, !4 = $char, !5 = $i, !6 = $set, !7 = $id, !8 = $insertTag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, '%3Cdiv%3EThis+is%3C%2Fdiv%3E+only+a+test+for+stackoverflow'
   12     2        ASSIGN                                                   !2, <false>
   13     3        ASSIGN                                                   !3, <false>
   14     4        ASSIGN                                                   !4, 0
   16     5        ASSIGN                                                   !5, 0
          6      > JMP                                                      ->90
   17     7    > > JMPZ_EX                                          ~15     !2, ->11
          8    >   FETCH_DIM_R                                      ~16     !1, !5
          9        IS_EQUAL                                         ~17     ~16, '%3E'
         10        BOOL                                             ~15     ~17
         11    > > JMPZ                                                     ~15, ->14
   18    12    >   ASSIGN                                                   !2, <false>
         13      > JMP                                                      ->71
   19    14    >   FETCH_DIM_R                                      ~19     !1, !5
         15        IS_EQUAL                                                 ~19, '%3C'
         16      > JMPZ                                                     ~20, ->32
   20    17    >   TYPE_CHECK                                  1018          !3
         18      > JMPZ                                                     ~21, ->30
   21    19    >   FETCH_DIM_RW                                     $22     !0, !3
         20        FETCH_DIM_RW                                     $23     $22, 0
         21        PRE_INC                                                  $23
   22    22        INIT_FCALL                                               'substr_replace'
         23        SEND_VAR                                                 !1
         24        SEND_VAL                                                 '%3C%2Fspan%3E'
         25        SEND_VAR                                                 !5
         26        SEND_VAL                                                 0
         27        DO_ICALL                                         $25     
         28        ASSIGN                                                   !1, $25
   23    29        ASSIGN_OP                                     1          !5, 6
   25    30    >   ASSIGN                                                   !2, <true>
         31      > JMP                                                      ->71
   27    32    > > FE_RESET_R                                       $29     !0, ->69
         33    > > FE_FETCH_R                                       ~30     $29, !6, ->69
         34    >   ASSIGN                                                   !7, ~30
   28    35        FETCH_DIM_R                                      ~32     !6, 0
         36        IS_EQUAL                                                 !4, ~32
         37      > JMPZ                                                     ~33, ->54
   29    38    >   ASSIGN                                                   !3, !7
   30    39        ROPE_INIT                                     3  ~36     '%3Cspan+class%3D%27annotation+n-'
         40        ROPE_ADD                                      1  ~36     ~36, !7
         41        ROPE_END                                      2  ~35     ~36, '%27%3E'
         42        ASSIGN                                                   !8, ~35
   31    43        STRLEN                                           ~39     !8
         44        SUB                                              ~40     ~39, 1
         45        ASSIGN_OP                                     1          !5, ~40
   32    46        INIT_FCALL                                               'substr_replace'
         47        SEND_VAR                                                 !1
         48        SEND_VAR                                                 !8
         49        SEND_VAR                                                 !4
         50        SEND_VAL                                                 0
         51        DO_ICALL                                         $42     
         52        ASSIGN                                                   !1, $42
         53      > JMP                                                      ->68
   33    54    >   IS_EQUAL                                         ~44     !3, !7
         55      > JMPZ_EX                                          ~44     ~44, ->59
         56    >   FETCH_DIM_R                                      ~45     !6, 1
         57        IS_EQUAL                                         ~46     !4, ~45
         58        BOOL                                             ~44     ~46
         59    > > JMPZ                                                     ~44, ->68
   34    60    >   INIT_FCALL                                               'substr_replace'
         61        SEND_VAR                                                 !1
         62        SEND_VAL                                                 '%3C%2Fspan%3E'
         63        SEND_VAR                                                 !4
         64        SEND_VAL                                                 0
         65        DO_ICALL                                         $47     
         66        ASSIGN                                                   !1, $47
   35    67        ASSIGN                                                   !3, <false>
   27    68    > > JMP                                                      ->33
         69    >   FE_FREE                                                  $29
   38    70        PRE_INC                                                  !4
   40    71    >   NOP                                                      
         72        FAST_CONCAT                                      ~51     !4, '%2C%09'
         73        ECHO                                                     ~51
   41    74      > JMPZ                                                     !2, ->77
         75    >   QM_ASSIGN                                        ~52     't'
         76      > JMP                                                      ->78
         77    >   QM_ASSIGN                                        ~52     'f'
         78    >   ECHO                                                     ~52
         79        ECHO                                                     '%2C%09'
   42    80        TYPE_CHECK                                    4          !3
         81      > JMPZ                                                     ~53, ->84
         82    >   QM_ASSIGN                                        ~54     'f'
         83      > JMP                                                      ->85
         84    >   QM_ASSIGN                                        ~54     !3
         85    >   ECHO                                                     ~54
         86        ECHO                                                     '%2C%09'
   43    87        ECHO                                                     !1
         88        ECHO                                                     '%0A'
   16    89        PRE_INC                                                  !5
         90    >   STRLEN                                           ~56     !1
         91        IS_SMALLER                                               !5, ~56
         92      > JMPNZ                                                    ~57, ->7
   46    93    >   ECHO                                                     !1
   47    94      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.96 ms | 1404 KiB | 15 Q