3v4l.org

run code in 500+ PHP versions simultaneously
<?php $bads = array('+11','- 68','[img','$cool', '# hash'); // disallowed full 'words'; if one of them appears in string, the function should return true $s= 'This is test to show if or $cool works but it does not'; //another example to test: $s= 'This - 68 is # hash not'; if(contains($s,$bads)) { echo 'Contains! '; } #### FUNCTION ### function contains($str, $bads) { //var_dump($bads); $b = "/"; foreach($bads as $a) { if(substr($a,0,1) == "$"){ $b .= preg_quote($a,'/'). "|"; }else{ $b .= "\b" . preg_quote($a,'/'). "\b|"; } } $b = substr($b, 0,-1) ."/"; echo $b; if(preg_match($b,$str, $m)){ var_dump($m); return true; } return false; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/C8KqP
function name:  (null)
number of ops:  9
compiled vars:  !0 = $bads, !1 = $s
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    5     1        ASSIGN                                                       !1, 'This+is+test+to+show+if+or+%24cool+works+but+it+does+not'
    8     2        INIT_FCALL_BY_NAME                                           'contains'
          3        SEND_VAR_EX                                                  !1
          4        SEND_VAR_EX                                                  !0
          5        DO_FCALL                                          0  $4      
          6      > JMPZ                                                         $4, ->8
    9     7    >   ECHO                                                         'Contains%21+'
   33     8    > > RETURN                                                       1

Function contains:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/C8KqP
function name:  contains
number of ops:  42
compiled vars:  !0 = $str, !1 = $bads, !2 = $b, !3 = $a, !4 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   17     2        ASSIGN                                                       !2, '%2F'
   18     3      > FE_RESET_R                                           $6      !1, ->24
          4    > > FE_FETCH_R                                                   $6, !3, ->24
   19     5    >   FRAMELESS_ICALL_3                substr              ~7      !3, 0
          6        OP_DATA                                                      1
          7        IS_EQUAL                                                     ~7, '%24'
          8      > JMPZ                                                         ~8, ->16
   20     9    >   INIT_FCALL                                                   'preg_quote'
         10        SEND_VAR                                                     !3
         11        SEND_VAL                                                     '%2F'
         12        DO_ICALL                                             $9      
         13        CONCAT                                               ~10     $9, '%7C'
         14        ASSIGN_OP                                         8          !2, ~10
   19    15      > JMP                                                          ->23
   22    16    >   INIT_FCALL                                                   'preg_quote'
         17        SEND_VAR                                                     !3
         18        SEND_VAL                                                     '%2F'
         19        DO_ICALL                                             $12     
         20        CONCAT                                               ~13     '%5Cb', $12
         21        CONCAT                                               ~14     ~13, '%5Cb%7C'
         22        ASSIGN_OP                                         8          !2, ~14
   18    23    > > JMP                                                          ->4
         24    >   FE_FREE                                                      $6
   25    25        FRAMELESS_ICALL_3                substr              ~16     !2, 0
         26        OP_DATA                                                      -1
         27        CONCAT                                               ~17     ~16, '%2F'
         28        ASSIGN                                                       !2, ~17
   26    29        ECHO                                                         !2
   27    30        INIT_FCALL                                                   'preg_match'
         31        SEND_VAR                                                     !2
         32        SEND_VAR                                                     !0
         33        SEND_REF                                                     !4
         34        DO_ICALL                                             $19     
         35      > JMPZ                                                         $19, ->40
   28    36    >   INIT_FCALL                                                   'var_dump'
         37        SEND_VAR                                                     !4
         38        DO_ICALL                                                     
   29    39      > RETURN                                                       <true>
   32    40    > > RETURN                                                       <false>
   33    41*     > RETURN                                                       null

End of function contains

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.4 ms | 2282 KiB | 16 Q