3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = 'The refugee said "dam!"'; $bad_words = array("fug","schnitt","dam"); array_walk($bad_words, function($value, $key) { // this prepares the regex, requires PHP 5.3+ I think. return preg_quote('~\b' . $value . '\b~i'); // \b means word boundary, like space, line-break, and I think period, dash, and many others. Prevends "refudgee" from being matched when searching for "fudge" }); $good_words = array("fudge","shoot","dang"); $good_text = preg_replace($bad_words,$good_words,$text);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k4KsJ
function name:  (null)
number of ops:  15
compiled vars:  !0 = $text, !1 = $bad_words, !2 = $good_words, !3 = $good_text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'The+refugee+said+%22dam%21%22'
    5     1        ASSIGN                                                   !1, <array>
    6     2        INIT_FCALL                                               'array_walk'
          3        SEND_REF                                                 !1
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fk4KsJ%3A6%240'
    8     5        SEND_VAL                                                 ~6
          6        DO_ICALL                                                 
   10     7        ASSIGN                                                   !2, <array>
   12     8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAR                                                 !1
         10        SEND_VAR                                                 !2
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !3, $9
         14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fk4KsJ%3A6%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k4KsJ
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $value, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_FCALL                                               'preg_quote'
          3        CONCAT                                           ~2      '%7E%5Cb', !0
          4        CONCAT                                           ~3      ~2, '%5Cb%7Ei'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7      > RETURN                                                   $4
    8     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fk4KsJ%3A6%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.85 ms | 1400 KiB | 19 Q