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); } echo "Index: ", $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 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 17
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 17
Branch analysis from position: 26
Branch analysis from position: 17
filename:       /in/cLll7
function name:  (null)
number of ops:  29
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                                                      ->23
   14    17    >   INIT_FCALL                                               'strpos'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !5
         21        DO_ICALL                                         $16     
         22        ASSIGN                                                   !5, $16
   13    23    >   POST_INC                                         ~18     !4
         24        IS_SMALLER                                               ~18, !1
         25      > JMPNZ                                                    ~19, ->17
   17    26    >   ECHO                                                     'Index%3A+'
         27        ECHO                                                     !5
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.43 ms | 1396 KiB | 17 Q