3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "Each person wants peaches for themselves forever"; $blacklist = array("for", "each"); //print_r($blacklist); // if you might have non-letter characters that have special meaning to the regex engine //$blacklist = array_map(function($v){return preg_quote($v, '/');}, $blacklist); //print_r($blacklist); echo "Without wordboundaries:\n"; var_export(preg_replace('/' . implode('|', $blacklist) . '/i', '', $string)); echo "\n\n---\n"; echo "With wordboundaries:\n"; var_export(preg_replace('/\b(?:' . implode('|', $blacklist) . ')\b/i', '', $string)); echo "\n\n---\n"; echo "With wordboundaries and consecutive space mop up:\n"; var_export(trim(preg_replace(array('/\b(?:' . implode('|', $blacklist) . ')\b/i', '/ \K +/'), '', $string)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Pui9I
function name:  (null)
number of ops:  55
compiled vars:  !0 = $string, !1 = $blacklist
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'Each+person+wants+peaches+for+themselves+forever'
    3     1        ASSIGN                                                   !1, <array>
    8     2        ECHO                                                     'Without+wordboundaries%3A%0A'
    9     3        INIT_FCALL                                               'var_export'
          4        INIT_FCALL                                               'preg_replace'
          5        INIT_FCALL                                               'implode'
          6        SEND_VAL                                                 '%7C'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $4      
          9        CONCAT                                           ~5      '%2F', $4
         10        CONCAT                                           ~6      ~5, '%2Fi'
         11        SEND_VAL                                                 ~6
         12        SEND_VAL                                                 ''
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $7      
         15        SEND_VAR                                                 $7
         16        DO_ICALL                                                 
   11    17        ECHO                                                     '%0A%0A---%0A'
   12    18        ECHO                                                     'With+wordboundaries%3A%0A'
   13    19        INIT_FCALL                                               'var_export'
         20        INIT_FCALL                                               'preg_replace'
         21        INIT_FCALL                                               'implode'
         22        SEND_VAL                                                 '%7C'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $9      
         25        CONCAT                                           ~10     '%2F%5Cb%28%3F%3A', $9
         26        CONCAT                                           ~11     ~10, '%29%5Cb%2Fi'
         27        SEND_VAL                                                 ~11
         28        SEND_VAL                                                 ''
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $12     
         31        SEND_VAR                                                 $12
         32        DO_ICALL                                                 
   15    33        ECHO                                                     '%0A%0A---%0A'
   16    34        ECHO                                                     'With+wordboundaries+and+consecutive+space+mop+up%3A%0A'
   17    35        INIT_FCALL                                               'var_export'
         36        INIT_FCALL                                               'trim'
         37        INIT_FCALL                                               'preg_replace'
         38        INIT_FCALL                                               'implode'
         39        SEND_VAL                                                 '%7C'
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                         $14     
         42        CONCAT                                           ~15     '%2F%5Cb%28%3F%3A', $14
         43        CONCAT                                           ~16     ~15, '%29%5Cb%2Fi'
         44        INIT_ARRAY                                       ~17     ~16
         45        ADD_ARRAY_ELEMENT                                ~17     '%2F+%5CK+%2B%2F'
         46        SEND_VAL                                                 ~17
         47        SEND_VAL                                                 ''
         48        SEND_VAR                                                 !0
         49        DO_ICALL                                         $18     
         50        SEND_VAR                                                 $18
         51        DO_ICALL                                         $19     
         52        SEND_VAR                                                 $19
         53        DO_ICALL                                                 
         54      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.25 ms | 1006 KiB | 17 Q