3v4l.org

run code in 300+ PHP versions simultaneously
<?php $searchTerm = "abcd"; $replaceTerm = "XXXX"; $test=array("${searchTerm}/${searchTerm}_.${searchTerm}", "xay${searchTerm}", "asdasd/$${searchTerm}.mp3", "${searchTerm}.", "blahahbasd${searchTerm}"); foreach ($test as $t) echo "$t => " . preg_replace("/(". preg_quote($searchTerm) . "([^_.])|". preg_quote($searchTerm) . "$)/x", preg_quote($replaceTerm) . "\${2}", $t) . "\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 49
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 49
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
filename:       /in/9lMGF
function name:  (null)
number of ops:  51
compiled vars:  !0 = $searchTerm, !1 = $replaceTerm, !2 = $test, !3 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'abcd'
    4     1        ASSIGN                                                   !1, 'XXXX'
    5     2        ROPE_INIT                                     5  ~7      !0
          3        ROPE_ADD                                      1  ~7      ~7, '%2F'
          4        ROPE_ADD                                      2  ~7      ~7, !0
          5        ROPE_ADD                                      3  ~7      ~7, '_.'
          6        ROPE_END                                      4  ~6      ~7, !0
          7        INIT_ARRAY                                       ~10     ~6
          8        NOP                                                      
          9        FAST_CONCAT                                      ~11     'xay', !0
         10        ADD_ARRAY_ELEMENT                                ~10     ~11
         11        ROPE_INIT                                     3  ~13     'asdasd%2F%24'
         12        ROPE_ADD                                      1  ~13     ~13, !0
         13        ROPE_END                                      2  ~12     ~13, '.mp3'
         14        ADD_ARRAY_ELEMENT                                ~10     ~12
         15        NOP                                                      
         16        FAST_CONCAT                                      ~15     !0, '.'
         17        ADD_ARRAY_ELEMENT                                ~10     ~15
         18        NOP                                                      
         19        FAST_CONCAT                                      ~16     'blahahbasd', !0
         20        ADD_ARRAY_ELEMENT                                ~10     ~16
         21        ASSIGN                                                   !2, ~10
    6    22      > FE_RESET_R                                       $18     !2, ->49
         23    > > FE_FETCH_R                                               $18, !3, ->49
    7    24    >   NOP                                                      
         25        FAST_CONCAT                                      ~19     !3, '+%3D%3E+'
         26        INIT_FCALL                                               'preg_replace'
         27        INIT_FCALL                                               'preg_quote'
         28        SEND_VAR                                                 !0
         29        DO_ICALL                                         $20     
         30        CONCAT                                           ~21     '%2F%28', $20
         31        CONCAT                                           ~22     ~21, '%28%5B%5E_.%5D%29%7C'
         32        INIT_FCALL                                               'preg_quote'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                         $23     
         35        CONCAT                                           ~24     ~22, $23
         36        CONCAT                                           ~25     ~24, '%24%29%2Fx'
         37        SEND_VAL                                                 ~25
         38        INIT_FCALL                                               'preg_quote'
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                         $26     
         41        CONCAT                                           ~27     $26, '%24%7B2%7D'
         42        SEND_VAL                                                 ~27
         43        SEND_VAR                                                 !3
         44        DO_ICALL                                         $28     
         45        CONCAT                                           ~29     ~19, $28
         46        CONCAT                                           ~30     ~29, '%0A'
         47        ECHO                                                     ~30
    6    48      > JMP                                                      ->23
         49    >   FE_FREE                                                  $18
    7    50      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.91 ms | 1400 KiB | 17 Q