3v4l.org

run code in 300+ 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:  48
compiled vars:  !0 = $string, !1 = $search, !2 = $replace
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   2     0  E >   QM_ASSIGN                                                !0
   3     1        QM_ASSIGN                                                !1
   4     2        QM_ASSIGN                                                !2
   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        ASSIGN_OBJ                                               $7
  10    11        ASSIGN_OBJ                                               '%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        ASSIGN_OBJ                                               $10
  16    24        ASSIGN_OBJ                                               '%0A---%0A'
  19    25        INIT_FCALL                                               'strrev'
        26        INIT_FCALL                                               'implode'
        27        INIT_FCALL                                               'strrev'
        28        SEND_VAR                                                 !2
        29        DO_ICALL                                         $11     
        30        SEND_VAR                                                 $11
        31        INIT_FCALL                                               'explode'
        32        INIT_FCALL                                               'strrev'
        33        SEND_VAR                                                 !1
        34        DO_ICALL                                         $12     
        35        SEND_VAR                                                 $12
        36        INIT_FCALL                                               'strrev'
        37        SEND_VAR                                                 !0
        38        DO_ICALL                                         $13     
        39        SEND_VAR                                                 $13
        40        SEND_VAL                                                 2
        41        DO_ICALL                                         $14     
        42        SEND_VAR                                                 $14
        43        DO_ICALL                                         $15     
        44        SEND_VAR                                                 $15
        45        DO_ICALL                                         $16     
        46        ASSIGN_OBJ                                               $16
  20    47      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
15.52 ms | 416 KiB | 7 Q