3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = 'III.OOO.OOO.S'; $search = 'OOO'; $replace = 'B'; //replace ONLY FIRST occurance of "OOO" with "B" echo substr_replace($string,$replace,0,strlen($search)); //$string => B.OOO.OOO.S echo "\n---\n"; //replace ONLY LAST occurance of "OOOO" with "B" echo substr_replace($string,$replace,strrpos($string,$search),strlen($search)); //$string => OOO.OOO.B.S echo "\n---\n"; //replace ONLY LAST occurance of "OOOO" with "B" echo strrev(implode(strrev($replace),explode(strrev($search),strrev($string),2))); //$string => OOO.OOO.B.S
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oIbRv
function name:  (null)
number of ops:  45
compiled vars:  !0 = $string, !1 = $search, !2 = $replace
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, 'III.OOO.OOO.S'
    3     1        ASSIGN                                                       !1, 'OOO'
    4     2        ASSIGN                                                       !2, 'B'
    7     3        INIT_FCALL                                                   'substr_replace'
          4        SEND_VAR                                                     !0
          5        SEND_VAR                                                     !2
          6        SEND_VAL                                                     0
          7        STRLEN                                               ~6      !1
          8        SEND_VAL                                                     ~6
          9        DO_ICALL                                             $7      
         10        ECHO                                                         $7
   10    11        ECHO                                                         '%0A---%0A'
   13    12        INIT_FCALL                                                   'substr_replace'
         13        SEND_VAR                                                     !0
         14        SEND_VAR                                                     !2
         15        INIT_FCALL                                                   'strrpos'
         16        SEND_VAR                                                     !0
         17        SEND_VAR                                                     !1
         18        DO_ICALL                                             $8      
         19        SEND_VAR                                                     $8
         20        STRLEN                                               ~9      !1
         21        SEND_VAL                                                     ~9
         22        DO_ICALL                                             $10     
         23        ECHO                                                         $10
   16    24        ECHO                                                         '%0A---%0A'
   19    25        INIT_FCALL                                                   'strrev'
         26        INIT_FCALL                                                   'strrev'
         27        SEND_VAR                                                     !2
         28        DO_ICALL                                             $11     
         29        INIT_FCALL                                                   'explode'
         30        INIT_FCALL                                                   'strrev'
         31        SEND_VAR                                                     !1
         32        DO_ICALL                                             $12     
         33        SEND_VAR                                                     $12
         34        INIT_FCALL                                                   'strrev'
         35        SEND_VAR                                                     !0
         36        DO_ICALL                                             $13     
         37        SEND_VAR                                                     $13
         38        SEND_VAL                                                     2
         39        DO_ICALL                                             $14     
         40        FRAMELESS_ICALL_2                implode             ~15     $11, $14
         41        SEND_VAL                                                     ~15
         42        DO_ICALL                                             $16     
         43        ECHO                                                         $16
   20    44      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.87 ms | 2125 KiB | 17 Q