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 = false; $repu = preg_replace_callback(array_map(function($w) { return '/\b' . preg_quote($w, '/') . '\b/i'; }, $badwords), function($match) use ($replaceChar) { $match_found = true; return str_repeat($replaceChar, strlen($match[0])); }, $text ); 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/CdVAJ
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                                                 
   17     9      > RETURN                                                   1

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

End of function filterbadwords

Function %00%7Bclosure%7D%2Fin%2FCdVAJ%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CdVAJ
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%2FCdVAJ%3A9%240

Function %00%7Bclosure%7D%2Fin%2FCdVAJ%3A10%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CdVAJ
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, <true>
   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%2FCdVAJ%3A10%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
201.91 ms | 1400 KiB | 23 Q