3v4l.org

run code in 500+ PHP versions simultaneously
<?php function badwords_full($string, &$bad_references) { static $bad_counter; static $bad_list; static $bad_list_q; if(!isset($bad_counter)) { $bad_counter = 0; $bad_list = badwords_list(); $bad_list_q = array_map('preg_quote', $bad_list); } return preg_replace_callback('~('.implode('|', $bad_list_q).')~', function($matches) use (&$bad_counter, &$bad_references) { $bad_counter++; $bad_references[$bad_counter] = $matches[0]; return mb_substr($matches[0], 0, 1).str_repeat('&squf;', strlen($matches[0]) - 1); }, $string); } function badwords_list() { # spanish $es = array( "gallina", "ñoño" ); # english $en = array( "chicken", "horse" ); # join all languages $list = array_merge($es, $en); usort($list, function($a,$b) { return strlen($b) < strlen($b); }); return $list; } echo badwords_full('Hola en español eres un ñoño!', $bad);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AnPJl
function name:  (null)
number of ops:  6
compiled vars:  !0 = $bad
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   39     0  E >   INIT_FCALL                                                   'badwords_full'
          1        SEND_VAL                                                     'Hola+en+espa%C3%B1ol+eres+un+%C3%B1o%C3%B1o%21'
          2        SEND_REF                                                     !0
          3        DO_FCALL                                          0  $1      
          4        ECHO                                                         $1
          5      > RETURN                                                       1

Function badwords_full:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/AnPJl
function name:  badwords_full
number of ops:  30
compiled vars:  !0 = $string, !1 = $bad_references, !2 = $bad_counter, !3 = $bad_list, !4 = $bad_list_q
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    3     2        BIND_STATIC                                                  !2
    4     3        BIND_STATIC                                                  !3
    5     4        BIND_STATIC                                                  !4
    6     5        ISSET_ISEMPTY_CV                                     ~5      !2
          6        BOOL_NOT                                             ~6      ~5
          7      > JMPZ                                                         ~6, ->17
    7     8    >   ASSIGN                                                       !2, 0
    8     9        INIT_FCALL_BY_NAME                                           'badwords_list'
         10        DO_FCALL                                          0  $8      
         11        ASSIGN                                                       !3, $8
    9    12        INIT_FCALL                                                   'array_map'
         13        SEND_VAL                                                     'preg_quote'
         14        SEND_VAR                                                     !3
         15        DO_ICALL                                             $10     
         16        ASSIGN                                                       !4, $10
   11    17    >   INIT_FCALL                                                   'preg_replace_callback'
         18        FRAMELESS_ICALL_2                implode             ~12     '%7C', !4
         19        CONCAT                                               ~13     '%7E%28', ~12
         20        CONCAT                                               ~14     ~13, '%29%7E'
         21        SEND_VAL                                                     ~14
   12    22        DECLARE_LAMBDA_FUNCTION                              ~15     [0]
         23        BIND_LEXICAL                                                 ~15, !2
         24        BIND_LEXICAL                                                 ~15, !1
   16    25        SEND_VAL                                                     ~15
         26        SEND_VAR                                                     !0
   11    27        DO_ICALL                                             $16     
   16    28      > RETURN                                                       $16
   17    29*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AnPJl
function name:  {closure:badwords_full():12}
number of ops:  23
compiled vars:  !0 = $matches, !1 = $bad_counter, !2 = $bad_references
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
   13     3        PRE_INC                                                      !1
   14     4        FETCH_DIM_R                                          ~5      !0, 0
          5        ASSIGN_DIM                                                   !2, !1
          6        OP_DATA                                                      ~5
   15     7        INIT_FCALL                                                   'mb_substr'
          8        FETCH_DIM_R                                          ~6      !0, 0
          9        SEND_VAL                                                     ~6
         10        SEND_VAL                                                     0
         11        SEND_VAL                                                     1
         12        DO_ICALL                                             $7      
         13        INIT_FCALL                                                   'str_repeat'
         14        SEND_VAL                                                     '%26squf%3B'
         15        FETCH_DIM_R                                          ~8      !0, 0
         16        STRLEN                                               ~9      ~8
         17        SUB                                                  ~10     ~9, 1
         18        SEND_VAL                                                     ~10
         19        DO_ICALL                                             $11     
         20        CONCAT                                               ~12     $7, $11
         21      > RETURN                                                       ~12
   16    22*     > RETURN                                                       null

End of Dynamic Function 0

End of function badwords_full

Function badwords_list:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AnPJl
function name:  badwords_list
number of ops:  14
compiled vars:  !0 = $es, !1 = $en, !2 = $list
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                       !0, <array>
   27     1        ASSIGN                                                       !1, <array>
   33     2        INIT_FCALL                                                   'array_merge'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_ICALL                                             $5      
          6        ASSIGN                                                       !2, $5
   34     7        INIT_FCALL                                                   'usort'
          8        SEND_REF                                                     !2
          9        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
   36    10        SEND_VAL                                                     ~7
   34    11        DO_ICALL                                                     
   37    12      > RETURN                                                       !2
   38    13*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AnPJl
function name:  {closure:badwords_list():34}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   35     2        STRLEN                                               ~2      !1
          3        STRLEN                                               ~3      !1
          4        IS_SMALLER                                           ~4      ~2, ~3
          5      > RETURN                                                       ~4
   36     6*     > RETURN                                                       null

End of Dynamic Function 0

End of function badwords_list

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.83 ms | 2757 KiB | 20 Q