3v4l.org

run code in 300+ PHP versions simultaneously
<?php $search = 'The'; $replace = 'A'; $subject = "The Quick Brown Fox Jumps Over The Lazy Dog's Thermos!"; function str_rreplace($search, $replace, $subject) { return (false !== $pos = strrpos($subject, $search)) ? substr_replace($subject, $replace, $pos, strlen($search)) : $subject; } function preg_rreplace($search, $replace, $subject) { preg_match_all($search, $subject, $matches, PREG_SET_ORDER); return ($lastMatch = end($matches)) ? str_rreplace($lastMatch[0], $replace, $subject) : $subject; } echo str_rreplace($search, $replace, $subject) . "\n---\n" . preg_rreplace($search, $replace, $subject);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lNU8R
function name:  (null)
number of ops:  17
compiled vars:  !0 = $search, !1 = $replace, !2 = $subject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'The'
    4     1        ASSIGN                                                   !1, 'A'
    5     2        ASSIGN                                                   !2, 'The+Quick+Brown+Fox+Jumps+Over+The+Lazy+Dog%27s+Thermos%21'
   16     3        INIT_FCALL                                               'str_rreplace'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $6      
   17     8        CONCAT                                           ~7      $6, '%0A---%0A'
   18     9        INIT_FCALL                                               'preg_rreplace'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !1
         12        SEND_VAR                                                 !2
         13        DO_FCALL                                      0  $8      
         14        CONCAT                                           ~9      ~7, $8
         15        ECHO                                                     ~9
         16      > RETURN                                                   1

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

End of function str_rreplace

Function preg_rreplace:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lNU8R
function name:  preg_rreplace
number of ops:  25
compiled vars:  !0 = $search, !1 = $replace, !2 = $subject, !3 = $matches, !4 = $lastMatch
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   12     3        INIT_FCALL                                               'preg_match_all'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !2
          6        SEND_REF                                                 !3
          7        SEND_VAL                                                 2
          8        DO_ICALL                                                 
   13     9        INIT_FCALL                                               'end'
         10        SEND_REF                                                 !3
         11        DO_ICALL                                         $6      
         12        ASSIGN                                           ~7      !4, $6
         13      > JMPZ                                                     ~7, ->22
         14    >   INIT_FCALL                                               'str_rreplace'
         15        FETCH_DIM_R                                      ~8      !4, 0
         16        SEND_VAL                                                 ~8
         17        SEND_VAR                                                 !1
         18        SEND_VAR                                                 !2
         19        DO_FCALL                                      0  $9      
         20        QM_ASSIGN                                        ~10     $9
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~10     !2
         23    > > RETURN                                                   ~10
   14    24*     > RETURN                                                   null

End of function preg_rreplace

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.93 ms | 1403 KiB | 24 Q