3v4l.org

run code in 500+ PHP versions simultaneously
<?php function preg_quote_replacement($str) { return addcslashes($str, '\\$'); } $text = 'Invoice: You owe me *#5* !'; $user_search = "*#5*"; $user_replace = "*$5*"; $search = preg_quote($user_search, "/"); $replace_bad1 = $user_replace; $replace_bad2 = preg_quote($user_replace); $replace_good = preg_quote_replacement($user_replace); $new_text1 = preg_replace("/$search/", $replace_bad1, $text); $new_text2 = preg_replace("/$search/", $replace_bad2, $text); $new_text3 = preg_replace("/$search/", $replace_good, $text); echo "Input: $text\nNew1: $new_text1\nNew2: $new_text2\nNew3: $new_text3\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZYue6
function name:  (null)
number of ops:  46
compiled vars:  !0 = $text, !1 = $user_search, !2 = $user_replace, !3 = $search, !4 = $replace_bad1, !5 = $replace_bad2, !6 = $replace_good, !7 = $new_text1, !8 = $new_text2, !9 = $new_text3
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                       !0, 'Invoice%3A+You+owe+me+%2A%235%2A+%21'
    8     1        ASSIGN                                                       !1, '%2A%235%2A'
    9     2        ASSIGN                                                       !2, '%2A%245%2A'
   11     3        INIT_FCALL                                                   'preg_quote'
          4        SEND_VAR                                                     !1
          5        SEND_VAL                                                     '%2F'
          6        DO_ICALL                                             $13     
          7        ASSIGN                                                       !3, $13
   12     8        ASSIGN                                                       !4, !2
   13     9        INIT_FCALL                                                   'preg_quote'
         10        SEND_VAR                                                     !2
         11        DO_ICALL                                             $16     
         12        ASSIGN                                                       !5, $16
   14    13        INIT_FCALL                                                   'preg_quote_replacement'
         14        SEND_VAR                                                     !2
         15        DO_FCALL                                          0  $18     
         16        ASSIGN                                                       !6, $18
   16    17        ROPE_INIT                                         3  ~21     '%2F'
         18        ROPE_ADD                                          1  ~21     ~21, !3
         19        ROPE_END                                          2  ~20     ~21, '%2F'
         20        FRAMELESS_ICALL_3                preg_replace        ~23     ~20, !4
         21        OP_DATA                                                      !0
         22        ASSIGN                                                       !7, ~23
   17    23        ROPE_INIT                                         3  ~26     '%2F'
         24        ROPE_ADD                                          1  ~26     ~26, !3
         25        ROPE_END                                          2  ~25     ~26, '%2F'
         26        FRAMELESS_ICALL_3                preg_replace        ~28     ~25, !5
         27        OP_DATA                                                      !0
         28        ASSIGN                                                       !8, ~28
   18    29        ROPE_INIT                                         3  ~31     '%2F'
         30        ROPE_ADD                                          1  ~31     ~31, !3
         31        ROPE_END                                          2  ~30     ~31, '%2F'
         32        FRAMELESS_ICALL_3                preg_replace        ~33     ~30, !6
         33        OP_DATA                                                      !0
         34        ASSIGN                                                       !9, ~33
   19    35        ROPE_INIT                                         9  ~36     'Input%3A+'
         36        ROPE_ADD                                          1  ~36     ~36, !0
         37        ROPE_ADD                                          2  ~36     ~36, '%0ANew1%3A++'
         38        ROPE_ADD                                          3  ~36     ~36, !7
         39        ROPE_ADD                                          4  ~36     ~36, '%0ANew2%3A++'
         40        ROPE_ADD                                          5  ~36     ~36, !8
         41        ROPE_ADD                                          6  ~36     ~36, '%0ANew3%3A++'
         42        ROPE_ADD                                          7  ~36     ~36, !9
         43        ROPE_END                                          8  ~35     ~36, '%0A'
         44        ECHO                                                         ~35
         45      > RETURN                                                       1

Function preg_quote_replacement:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZYue6
function name:  preg_quote_replacement
number of ops:  7
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        INIT_FCALL                                                   'addcslashes'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     '%5C%24'
          4        DO_ICALL                                             $1      
          5      > RETURN                                                       $1
    5     6*     > RETURN                                                       null

End of function preg_quote_replacement

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
145.94 ms | 2603 KiB | 16 Q