3v4l.org

run code in 300+ 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 = 27
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 27
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 46
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/C8KqP
function name:  contains
number of ops:  48
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, ->27
          4    > > FE_FETCH_R                                               $6, !3, ->27
   19     5    >   INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !3
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 1
          9        DO_ICALL                                         $7      
         10        IS_EQUAL                                                 $7, '%24'
         11      > JMPZ                                                     ~8, ->19
   20    12    >   INIT_FCALL                                               'preg_quote'
         13        SEND_VAR                                                 !3
         14        SEND_VAL                                                 '%2F'
         15        DO_ICALL                                         $9      
         16        CONCAT                                           ~10     $9, '%7C'
         17        ASSIGN_OP                                     8          !2, ~10
   19    18      > JMP                                                      ->26
   22    19    >   INIT_FCALL                                               'preg_quote'
         20        SEND_VAR                                                 !3
         21        SEND_VAL                                                 '%2F'
         22        DO_ICALL                                         $12     
         23        CONCAT                                           ~13     '%5Cb', $12
         24        CONCAT                                           ~14     ~13, '%5Cb%7C'
         25        ASSIGN_OP                                     8          !2, ~14
   18    26    > > JMP                                                      ->4
         27    >   FE_FREE                                                  $6
   25    28        INIT_FCALL                                               'substr'
         29        SEND_VAR                                                 !2
         30        SEND_VAL                                                 0
         31        SEND_VAL                                                 -1
         32        DO_ICALL                                         $16     
         33        CONCAT                                           ~17     $16, '%2F'
         34        ASSIGN                                                   !2, ~17
   26    35        ECHO                                                     !2
   27    36        INIT_FCALL                                               'preg_match'
         37        SEND_VAR                                                 !2
         38        SEND_VAR                                                 !0
         39        SEND_REF                                                 !4
         40        DO_ICALL                                         $19     
         41      > JMPZ                                                     $19, ->46
   28    42    >   INIT_FCALL                                               'var_dump'
         43        SEND_VAR                                                 !4
         44        DO_ICALL                                                 
   29    45      > RETURN                                                   <true>
   32    46    > > RETURN                                                   <false>
   33    47*     > RETURN                                                   null

End of function contains

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
255.05 ms | 1010 KiB | 17 Q