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}", "1234${searchTerm}1234", "${searchTerm}"); foreach ($test as $t) echo "$t => " . preg_replace("/". preg_quote($searchTerm) . "([^_.]|$)/x", preg_quote($replaceTerm) . "\${1}", $t) . "\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 50
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 50
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
filename:       /in/kNWYg
function name:  (null)
number of ops:  52
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'
         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        ROPE_INIT                                     3  ~18     '1234'
         22        ROPE_ADD                                      1  ~18     ~18, !0
         23        ROPE_END                                      2  ~17     ~18, '1234'
         24        ADD_ARRAY_ELEMENT                                ~10     ~17
         25        CAST                                          6  ~20     !0
         26        ADD_ARRAY_ELEMENT                                ~10     ~20
         27        ASSIGN                                                   !2, ~10
    6    28      > FE_RESET_R                                       $22     !2, ->50
         29    > > FE_FETCH_R                                               $22, !3, ->50
    7    30    >   NOP                                                      
         31        FAST_CONCAT                                      ~23     !3, '+%3D%3E+'
         32        INIT_FCALL                                               'preg_replace'
         33        INIT_FCALL                                               'preg_quote'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $24     
         36        CONCAT                                           ~25     '%2F', $24
         37        CONCAT                                           ~26     ~25, '%28%5B%5E_.%5D%7C%24%29%2Fx'
         38        SEND_VAL                                                 ~26
         39        INIT_FCALL                                               'preg_quote'
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                         $27     
         42        CONCAT                                           ~28     $27, '%24%7B1%7D'
         43        SEND_VAL                                                 ~28
         44        SEND_VAR                                                 !3
         45        DO_ICALL                                         $29     
         46        CONCAT                                           ~30     ~23, $29
         47        CONCAT                                           ~31     ~30, '%0A'
         48        ECHO                                                     ~31
    6    49      > JMP                                                      ->29
         50    >   FE_FREE                                                  $22
    7    51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.28 ms | 1400 KiB | 17 Q