3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = "test.string.1.sometext.more"; $startingOffset = 5; $pattern = '~^.{' . $startingOffset . '}[^.]*\K\.~'; $replacement = 2; echo preg_replace($pattern, $replacement, $str); echo "\n---\n"; $offset = strpos($str, '.', $startingOffset); if ($offset !== false) { $str[$offset] = $replacement; } echo $str;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/jClan
function name:  (null)
number of ops:  19
compiled vars:  !0 = $str, !1 = $startingOffset, !2 = $pattern, !3 = $replacement, !4 = $offset
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'test.string.1.sometext.more'
    4     1        ASSIGN                                                       !1, 5
    5     2        CONCAT                                               ~7      '%7E%5E.%7B', !1
          3        CONCAT                                               ~8      ~7, '%7D%5B%5E.%5D%2A%5CK%5C.%7E'
          4        ASSIGN                                                       !2, ~8
    6     5        ASSIGN                                                       !3, 2
    7     6        FRAMELESS_ICALL_3                preg_replace        ~11     !2, !3
          7        OP_DATA                                                      !0
          8        ECHO                                                         ~11
    9     9        ECHO                                                         '%0A---%0A'
   11    10        FRAMELESS_ICALL_3                strpos              ~12     !0, '.'
         11        OP_DATA                                                      !1
         12        ASSIGN                                                       !4, ~12
   12    13        TYPE_CHECK                                      1018          !4
         14      > JMPZ                                                         ~14, ->17
   13    15    >   ASSIGN_DIM                                                   !0, !4
         16        OP_DATA                                                      !3
   15    17    >   ECHO                                                         !0
   16    18      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.56 ms | 3328 KiB | 13 Q