3v4l.org

run code in 300+ PHP versions simultaneously
<?php class php { /** * str_replace() from the end of a string that can also be limited e.g. replace only the last instance of '</div>' with '' * * @param string $find * @param string $replace * @param string $subject * @param int $replacement_limit | -1 to replace all references * * @return string */ public static function str_replace($find, $replace, $subject, $replacement_limit = -1) { $find_pattern = str_replace('/', '\/', $find); return preg_replace('/' . $find_pattern . '/', $replace, $subject, $replacement_limit); } /** * str_replace() from the end of a string that can also be limited e.g. replace only the last instance of '</div>' with '' * * @param string $find * @param string $replace * @param string $subject * @param int $replacement_limit | -1 to replace all references * * @return string */ public static function str_rreplace($find, $replace, $subject, $replacement_limit = -1) { return strrev( self::str_replace(strrev($find), strrev($replace), strrev($subject), $replacement_limit) ); } } $find = '$'; $replace = 'dollar'; $subject = 'This is a $ symbol. I like making $s.'; echo php::str_replace($find, $replace, $subject);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dTdYK
function name:  (null)
number of ops:  10
compiled vars:  !0 = $find, !1 = $replace, !2 = $subject
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, '%24'
   34     1        ASSIGN                                                   !1, 'dollar'
   35     2        ASSIGN                                                   !2, 'This+is+a+%24+symbol.+I+like+making+%24s.'
   36     3        INIT_STATIC_METHOD_CALL                                  'php', 'str_replace'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $6      
          8        ECHO                                                     $6
          9      > RETURN                                                   1

Class php:
Function str_replace:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dTdYK
function name:  str_replace
number of ops:  20
compiled vars:  !0 = $find, !1 = $replace, !2 = $subject, !3 = $replacement_limit, !4 = $find_pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      -1
   15     4        INIT_FCALL                                               'str_replace'
          5        SEND_VAL                                                 '%2F'
          6        SEND_VAL                                                 '%5C%2F'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !4, $5
   16    10        INIT_FCALL                                               'preg_replace'
         11        CONCAT                                           ~7      '%2F', !4
         12        CONCAT                                           ~8      ~7, '%2F'
         13        SEND_VAL                                                 ~8
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !2
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $9      
         18      > RETURN                                                   $9
   17    19*     > RETURN                                                   null

End of function str_replace

Function str_rreplace:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dTdYK
function name:  str_rreplace
number of ops:  24
compiled vars:  !0 = $find, !1 = $replace, !2 = $subject, !3 = $replacement_limit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      -1
   30     4        INIT_FCALL                                               'strrev'
          5        INIT_STATIC_METHOD_CALL                                  'str_replace'
          6        INIT_FCALL                                               'strrev'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $4      
          9        SEND_VAR                                                 $4
         10        INIT_FCALL                                               'strrev'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $5      
         13        SEND_VAR                                                 $5
         14        INIT_FCALL                                               'strrev'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $6      
         17        SEND_VAR                                                 $6
         18        SEND_VAR                                                 !3
         19        DO_FCALL                                      0  $7      
         20        SEND_VAR                                                 $7
         21        DO_ICALL                                         $8      
         22      > RETURN                                                   $8
   31    23*     > RETURN                                                   null

End of function str_rreplace

End of class php.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.65 ms | 1392 KiB | 19 Q