3v4l.org

run code in 300+ PHP versions simultaneously
<?php $searchTerm = "abcd"; $replaceTerm = "XXXX"; $test=array("$searchTerm/$searchTerm_.mp3", "$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 = 24, Position 2 = 50
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 50
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
filename:       /in/fR8oX
function name:  (null)
number of ops:  52
compiled vars:  !0 = $searchTerm, !1 = $replaceTerm, !2 = $test, !3 = $searchTerm_, !4 = $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                                     4  ~8      !0
          3        ROPE_ADD                                      1  ~8      ~8, '%2F'
          4        ROPE_ADD                                      2  ~8      ~8, !3
          5        ROPE_END                                      3  ~7      ~8, '.mp3'
          6        INIT_ARRAY                                       ~10     ~7
          7        CAST                                          6  ~11     !0
          8        ADD_ARRAY_ELEMENT                                ~10     ~11
          9        NOP                                                      
         10        FAST_CONCAT                                      ~12     'xay', !0
         11        ADD_ARRAY_ELEMENT                                ~10     ~12
         12        ROPE_INIT                                     3  ~14     'asdasd%2F'
         13        ROPE_ADD                                      1  ~14     ~14, !0
         14        ROPE_END                                      2  ~13     ~14, '.mp3'
         15        ADD_ARRAY_ELEMENT                                ~10     ~13
         16        NOP                                                      
         17        FAST_CONCAT                                      ~16     !0, '.'
         18        ADD_ARRAY_ELEMENT                                ~10     ~16
         19        NOP                                                      
         20        FAST_CONCAT                                      ~17     'blahahbasd', !0
         21        ADD_ARRAY_ELEMENT                                ~10     ~17
         22        ASSIGN                                                   !2, ~10
    6    23      > FE_RESET_R                                       $19     !2, ->50
         24    > > FE_FETCH_R                                               $19, !4, ->50
    7    25    >   NOP                                                      
         26        FAST_CONCAT                                      ~20     !4, '+%3D%3E+'
         27        INIT_FCALL                                               'preg_replace'
         28        INIT_FCALL                                               'preg_quote'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $21     
         31        CONCAT                                           ~22     '%2F%28', $21
         32        CONCAT                                           ~23     ~22, '%28%5B%5E_.%5D%29%7C'
         33        INIT_FCALL                                               'preg_quote'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $24     
         36        CONCAT                                           ~25     ~23, $24
         37        CONCAT                                           ~26     ~25, '%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%7B2%7D'
         43        SEND_VAL                                                 ~28
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                         $29     
         46        CONCAT                                           ~30     ~20, $29
         47        CONCAT                                           ~31     ~30, '%0A'
         48        ECHO                                                     ~31
    6    49      > JMP                                                      ->24
         50    >   FE_FREE                                                  $19
    7    51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.35 ms | 1400 KiB | 17 Q