3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "[vc_tab [vc_tab [vc_tab [vc_tab [vc_tab [vc_tab"; $active = 3; $needle = "[vc_tab"; $replace = '[vc_tab active="true"'; if( substr_count( $string, $needle) < $active) { throw new Exception("There aren't enough needles in the string to do this replacement"); } $count = 0; $index = 0; while( $count++ < $active) { $index = strpos( $string, $needle, $index) + strlen( $needle); } echo "Index: ", $index, " ", substr( $string, $index);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 17
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 17
Branch analysis from position: 28
Branch analysis from position: 17
filename:       /in/UWlmC
function name:  (null)
number of ops:  37
compiled vars:  !0 = $string, !1 = $active, !2 = $needle, !3 = $replace, !4 = $count, !5 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5Bvc_tab+%5Bvc_tab+%5Bvc_tab+%5Bvc_tab+%5Bvc_tab+%5Bvc_tab'
    4     1        ASSIGN                                                   !1, 3
    5     2        ASSIGN                                                   !2, '%5Bvc_tab'
    6     3        ASSIGN                                                   !3, '%5Bvc_tab+active%3D%22true%22'
    8     4        INIT_FCALL                                               'substr_count'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $10     
          8        IS_SMALLER                                               $10, !1
          9      > JMPZ                                                     ~11, ->14
    9    10    >   NEW                                              $12     'Exception'
         11        SEND_VAL_EX                                              'There+aren%27t+enough+needles+in+the+string+to+do+this+replacement'
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $12
   12    14    >   ASSIGN                                                   !4, 0
         15        ASSIGN                                                   !5, 0
   13    16      > JMP                                                      ->25
   14    17    >   INIT_FCALL                                               'strpos'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !5
         21        DO_ICALL                                         $16     
         22        STRLEN                                           ~17     !2
         23        ADD                                              ~18     $16, ~17
         24        ASSIGN                                                   !5, ~18
   13    25    >   POST_INC                                         ~20     !4
         26        IS_SMALLER                                               ~20, !1
         27      > JMPNZ                                                    ~21, ->17
   17    28    >   ECHO                                                     'Index%3A+'
         29        ECHO                                                     !5
         30        ECHO                                                     '+'
         31        INIT_FCALL                                               'substr'
         32        SEND_VAR                                                 !0
         33        SEND_VAR                                                 !5
         34        DO_ICALL                                         $22     
         35        ECHO                                                     $22
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.57 ms | 1400 KiB | 19 Q