3v4l.org

run code in 300+ PHP versions simultaneously
<?php $badwords = array('dog', 'dala', 'bad3', 'ass'); $text = 'This is a dog. . Grass. is good but ass is bad.'; print_r( filterBadwords($text,$badwords)); function filterBadwords($text, array $badwords, $replaceChar = '*') { //$match_found = 0; $repu = preg_replace_callback(array_map(function($w) { return '/\b' . preg_quote($w, '/') . '\b/i'; }, $badwords), function($match) use ($replaceChar) { $match_found = 1; return str_repeat($replaceChar, strlen($match[0])); }, $text ); if(strcasecmp($repu,$text) === 0) echo "ok"; else echo "not ok"; return array('error' =>$match_found, 'text' => $repu ); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1P1PY
function name:  (null)
number of ops:  10
compiled vars:  !0 = $badwords, !1 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !1, 'This+is+a+dog.+.+Grass.+is+good+but+ass+is+bad.'
    4     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL_BY_NAME                                       'filterBadwords'
          4        SEND_VAR_EX                                              !1
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   21     9      > RETURN                                                   1

Function filterbadwords:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1P1PY
function name:  filterBadwords
number of ops:  29
compiled vars:  !0 = $text, !1 = $badwords, !2 = $replaceChar, !3 = $repu, !4 = $match_found
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%2A'
    9     3        INIT_FCALL                                               'preg_replace_callback'
          4        INIT_FCALL                                               'array_map'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1P1PY%3A9%240'
          6        SEND_VAL                                                 ~5
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $6      
          9        SEND_VAR                                                 $6
   10    10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1P1PY%3A10%241'
         11        BIND_LEXICAL                                             ~7, !2
   12    12        SEND_VAL                                                 ~7
   13    13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $8      
    9    15        ASSIGN                                                   !3, $8
   16    16        INIT_FCALL                                               'strcasecmp'
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $10     
         20        IS_IDENTICAL                                             $10, 0
         21      > JMPZ                                                     ~11, ->24
   17    22    >   ECHO                                                     'ok'
         23      > JMP                                                      ->25
   19    24    >   ECHO                                                     'not+ok'
   20    25    >   INIT_ARRAY                                       ~12     !4, 'error'
         26        ADD_ARRAY_ELEMENT                                ~12     !3, 'text'
         27      > RETURN                                                   ~12
   21    28*     > RETURN                                                   null

End of function filterbadwords

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

End of function %00%7Bclosure%7D%2Fin%2F1P1PY%3A9%240

Function %00%7Bclosure%7D%2Fin%2F1P1PY%3A10%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1P1PY
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $match, !1 = $replaceChar, !2 = $match_found
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   11     2        ASSIGN                                                   !2, 1
   12     3        INIT_FCALL                                               'str_repeat'
          4        SEND_VAR                                                 !1
          5        FETCH_DIM_R                                      ~4      !0, 0
          6        STRLEN                                           ~5      ~4
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9      > RETURN                                                   $6
         10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1P1PY%3A10%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.15 ms | 1400 KiB | 25 Q