3v4l.org

run code in 300+ 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:  55
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        INIT_FCALL                                               'preg_replace'
         18        ROPE_INIT                                     3  ~21     '%2F'
         19        ROPE_ADD                                      1  ~21     ~21, !3
         20        ROPE_END                                      2  ~20     ~21, '%2F'
         21        SEND_VAL                                                 ~20
         22        SEND_VAR                                                 !4
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $23     
         25        ASSIGN                                                   !7, $23
   17    26        INIT_FCALL                                               'preg_replace'
         27        ROPE_INIT                                     3  ~26     '%2F'
         28        ROPE_ADD                                      1  ~26     ~26, !3
         29        ROPE_END                                      2  ~25     ~26, '%2F'
         30        SEND_VAL                                                 ~25
         31        SEND_VAR                                                 !5
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $28     
         34        ASSIGN                                                   !8, $28
   18    35        INIT_FCALL                                               'preg_replace'
         36        ROPE_INIT                                     3  ~31     '%2F'
         37        ROPE_ADD                                      1  ~31     ~31, !3
         38        ROPE_END                                      2  ~30     ~31, '%2F'
         39        SEND_VAL                                                 ~30
         40        SEND_VAR                                                 !6
         41        SEND_VAR                                                 !0
         42        DO_ICALL                                         $33     
         43        ASSIGN                                                   !9, $33
   19    44        ROPE_INIT                                     9  ~36     'Input%3A+'
         45        ROPE_ADD                                      1  ~36     ~36, !0
         46        ROPE_ADD                                      2  ~36     ~36, '%0ANew1%3A++'
         47        ROPE_ADD                                      3  ~36     ~36, !7
         48        ROPE_ADD                                      4  ~36     ~36, '%0ANew2%3A++'
         49        ROPE_ADD                                      5  ~36     ~36, !8
         50        ROPE_ADD                                      6  ~36     ~36, '%0ANew3%3A++'
         51        ROPE_ADD                                      7  ~36     ~36, !9
         52        ROPE_END                                      8  ~35     ~36, '%0A'
         53        ECHO                                                     ~35
         54      > 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.0.0


preferences:
168.53 ms | 1394 KiB | 20 Q