3v4l.org

run code in 500+ PHP versions simultaneously
<?php $find = Array( 0 => 'Lorem Ipsum', 1 => 'Lorem Ipsum', 2 => 'typesetting', 3 => 'dummy' , 4 => 'dummy' ); $replace = Array( 0 => 'style1', 1 => 'style2', 2 => 'style3', 3 => 'style4', 4 => 'style5' ); $string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."; function str_replace_first($search, $replace, $subject) { if (($pos = strpos($subject, $search)) !== false) { return substr_replace($subject, $replace, $pos, strlen($search)); } return $subject; } $result = $string; foreach ($find as $key => $search) { $result = str_replace_first($search, $replace[$key], $result); } echo $result;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/F8hZC
function name:  (null)
number of ops:  18
compiled vars:  !0 = $find, !1 = $replace, !2 = $string, !3 = $result, !4 = $search, !5 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   11     1        ASSIGN                                                       !1, <array>
   19     2        ASSIGN                                                       !2, 'Lorem+Ipsum+is+simply+dummy+text+of+the+printing+and+typesetting+industry.+%0A+++++++++++Lorem+Ipsum+has+been+the+industry%27s+standard+dummy+text+ever+since+the+1500s%2C+%0A+++++++++++when+an+unknown+printer+took+a+galley+of+type+and+scrambled+it+to+make+a+type+specimen+book.'
   30     3        ASSIGN                                                       !3, !2
   31     4      > FE_RESET_R                                           $10     !0, ->15
          5    > > FE_FETCH_R                                           ~11     $10, !4, ->15
          6    >   ASSIGN                                                       !5, ~11
   32     7        INIT_FCALL                                                   'str_replace_first'
          8        SEND_VAR                                                     !4
          9        FETCH_DIM_R                                          ~13     !1, !5
         10        SEND_VAL                                                     ~13
         11        SEND_VAR                                                     !3
         12        DO_FCALL                                          0  $14     
         13        ASSIGN                                                       !3, $14
   31    14      > JMP                                                          ->5
         15    >   FE_FREE                                                      $10
   34    16        ECHO                                                         !3
   35    17      > RETURN                                                       1

Function str_replace_first:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F8hZC
function name:  str_replace_first
number of ops:  17
compiled vars:  !0 = $search, !1 = $replace, !2 = $subject, !3 = $pos
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   24     3        FRAMELESS_ICALL_2                strpos              ~4      !2, !0
          4        ASSIGN                                               ~5      !3, ~4
          5        TYPE_CHECK                                      1018          ~5
          6      > JMPZ                                                         ~6, ->15
   25     7    >   INIT_FCALL                                                   'substr_replace'
          8        SEND_VAR                                                     !2
          9        SEND_VAR                                                     !1
         10        SEND_VAR                                                     !3
         11        STRLEN                                               ~7      !0
         12        SEND_VAL                                                     ~7
         13        DO_ICALL                                             $8      
         14      > RETURN                                                       $8
   27    15    > > RETURN                                                       !2
   28    16*     > RETURN                                                       null

End of function str_replace_first

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.12 ms | 2209 KiB | 17 Q