3v4l.org

run code in 300+ PHP versions simultaneously
<?php $haystack = 'abdabc'; $needle = 'c'; $replace = 'z'; $limit = 2; function str_replace_limit($haystack, $needle, $replace, $limit, $start_pos = 0) { if ($limit < 1 || ($pos = strpos($haystack,$needle,$start_pos)) === false) { return $haystack; } else { return str_replace_limit( substr_replace($haystack, $replace, $pos, strlen($needle)), $needle, $replace, $limit - 1, $pos + strlen($replace) ); } } echo str_replace_limit($haystack, $needle, $replace, $limit);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Kdmqp
function name:  (null)
number of ops:  12
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $replace, !3 = $limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'abdabc'
    3     1        ASSIGN                                                   !1, 'c'
    4     2        ASSIGN                                                   !2, 'z'
    5     3        ASSIGN                                                   !3, 2
   21     4        INIT_FCALL                                               'str_replace_limit'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !2
          8        SEND_VAR                                                 !3
          9        DO_FCALL                                      0  $8      
         10        ECHO                                                     $8
         11      > RETURN                                                   1

Function str_replace_limit:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/Kdmqp
function name:  str_replace_limit
number of ops:  37
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $replace, !3 = $limit, !4 = $start_pos, !5 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV_INIT                                        !4      0
    8     5        IS_SMALLER                                       ~6      !3, 1
          6      > JMPNZ_EX                                         ~6      ~6, ->15
          7    >   INIT_FCALL                                               'strpos'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        SEND_VAR                                                 !4
         11        DO_ICALL                                         $7      
         12        ASSIGN                                           ~8      !5, $7
         13        TYPE_CHECK                                    4  ~9      ~8
         14        BOOL                                             ~6      ~9
         15    > > JMPZ                                                     ~6, ->18
    9    16    > > RETURN                                                   !0
         17*       JMP                                                      ->36
   11    18    >   INIT_FCALL_BY_NAME                                       'str_replace_limit'
   12    19        INIT_FCALL                                               'substr_replace'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !2
         22        SEND_VAR                                                 !5
         23        STRLEN                                           ~10     !1
         24        SEND_VAL                                                 ~10
         25        DO_ICALL                                         $11     
         26        SEND_VAR_NO_REF_EX                                       $11
         27        SEND_VAR_EX                                              !1
         28        SEND_VAR_EX                                              !2
   15    29        SUB                                              ~12     !3, 1
         30        SEND_VAL_EX                                              ~12
   16    31        STRLEN                                           ~13     !2
         32        ADD                                              ~14     !5, ~13
         33        SEND_VAL_EX                                              ~14
         34        DO_FCALL                                      0  $15     
         35      > RETURN                                                   $15
   19    36*     > RETURN                                                   null

End of function str_replace_limit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.37 ms | 1403 KiB | 18 Q