3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test=array("abcd/abcd_.mp3", "abcd", "asdasd/abcd.mp3", "abcd.", "blahahbasdabcd"); $searchTerm = "abcd"; $replaceTerm = "XXXX"; 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 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 30
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/Fth56
function name:  (null)
number of ops:  32
compiled vars:  !0 = $test, !1 = $searchTerm, !2 = $replaceTerm, !3 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !1, 'abcd'
    4     2        ASSIGN                                                   !2, 'XXXX'
    5     3      > FE_RESET_R                                       $7      !0, ->30
          4    > > FE_FETCH_R                                               $7, !3, ->30
    6     5    >   NOP                                                      
          6        FAST_CONCAT                                      ~8      !3, '+%3D%3E+'
          7        INIT_FCALL                                               'preg_replace'
          8        INIT_FCALL                                               'preg_quote'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $9      
         11        CONCAT                                           ~10     '%2F%28', $9
         12        CONCAT                                           ~11     ~10, '%28%5B%5E_.%5D%29%7C'
         13        INIT_FCALL                                               'preg_quote'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $12     
         16        CONCAT                                           ~13     ~11, $12
         17        CONCAT                                           ~14     ~13, '%24%29%2Fx'
         18        SEND_VAL                                                 ~14
         19        INIT_FCALL                                               'preg_quote'
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $15     
         22        CONCAT                                           ~16     $15, '%24%7B2%7D'
         23        SEND_VAL                                                 ~16
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $17     
         26        CONCAT                                           ~18     ~8, $17
         27        CONCAT                                           ~19     ~18, '%0A'
         28        ECHO                                                     ~19
    5    29      > JMP                                                      ->4
         30    >   FE_FREE                                                  $7
    6    31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.35 ms | 1396 KiB | 17 Q