3v4l.org

run code in 300+ PHP versions simultaneously
<?php $bads = [ '+11', '- 68', '[img', '$cool ', '# hash' ]; $tests = []; foreach ($bads as $bad) { $tests["A $bad B"] = true; $tests["$bad"] = true; $tests["A $bad"] = true; $tests["$bad B"] = true; $tests["x${bad}x"] = false; $tests["x${bad}"] = false; $tests["${bad}x"] = false; } foreach ($tests as $string => $expected) { $expect = (int)$expected; $actual = (int)contains($string, $bads); if ($actual !== $expect) { echo "FAIL: '$string' should be $expect, is $actual"; } else { echo "PASS: '$string' was expected $expect"; } echo PHP_EOL; } #### FUNCTION ### function contains($str, $bads) { $template = '/(\s+%1$s\s+|^\s*%1$s\s+|\s+%1$s\s*$|^\s*%1$s\s*$)/'; foreach ($bads as $a) { $regex = sprintf($template, preg_quote($a, '/')); if ($x = preg_match($regex, $str, $matches)) { return true; } } return false; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 34
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 63
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 63
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 56
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
Branch analysis from position: 34
filename:       /in/RH6r3
function name:  (null)
number of ops:  65
compiled vars:  !0 = $bads, !1 = $tests, !2 = $bad, !3 = $expected, !4 = $string, !5 = $expect, !6 = $actual
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    6     2      > FE_RESET_R                                       $9      !0, ->34
          3    > > FE_FETCH_R                                               $9, !2, ->34
    7     4    >   ROPE_INIT                                     3  ~11     'A+'
          5        ROPE_ADD                                      1  ~11     ~11, !2
          6        ROPE_END                                      2  ~10     ~11, '+B'
          7        ASSIGN_DIM                                               !1, ~10
          8        OP_DATA                                                  <true>
    8     9        CAST                                          6  ~14     !2
         10        ASSIGN_DIM                                               !1, ~14
         11        OP_DATA                                                  <true>
    9    12        NOP                                                      
         13        FAST_CONCAT                                      ~16     'A+', !2
         14        ASSIGN_DIM                                               !1, ~16
         15        OP_DATA                                                  <true>
   10    16        NOP                                                      
         17        FAST_CONCAT                                      ~18     !2, '+B'
         18        ASSIGN_DIM                                               !1, ~18
         19        OP_DATA                                                  <true>
   11    20        ROPE_INIT                                     3  ~21     'x'
         21        ROPE_ADD                                      1  ~21     ~21, !2
         22        ROPE_END                                      2  ~20     ~21, 'x'
         23        ASSIGN_DIM                                               !1, ~20
         24        OP_DATA                                                  <false>
   12    25        NOP                                                      
         26        FAST_CONCAT                                      ~24     'x', !2
         27        ASSIGN_DIM                                               !1, ~24
         28        OP_DATA                                                  <false>
   13    29        NOP                                                      
         30        FAST_CONCAT                                      ~26     !2, 'x'
         31        ASSIGN_DIM                                               !1, ~26
         32        OP_DATA                                                  <false>
    6    33      > JMP                                                      ->3
         34    >   FE_FREE                                                  $9
   16    35      > FE_RESET_R                                       $28     !1, ->63
         36    > > FE_FETCH_R                                       ~29     $28, !3, ->63
         37    >   ASSIGN                                                   !4, ~29
   17    38        CAST                                          4  ~31     !3
         39        ASSIGN                                                   !5, ~31
   18    40        INIT_FCALL_BY_NAME                                       'contains'
         41        SEND_VAR_EX                                              !4
         42        SEND_VAR_EX                                              !0
         43        DO_FCALL                                      0  $33     
         44        CAST                                          4  ~34     $33
         45        ASSIGN                                                   !6, ~34
   19    46        IS_NOT_IDENTICAL                                         !6, !5
         47      > JMPZ                                                     ~36, ->56
   20    48    >   ROPE_INIT                                     6  ~38     'FAIL%3A+%27'
         49        ROPE_ADD                                      1  ~38     ~38, !4
         50        ROPE_ADD                                      2  ~38     ~38, '%27+should+be+'
         51        ROPE_ADD                                      3  ~38     ~38, !5
         52        ROPE_ADD                                      4  ~38     ~38, '%2C+is+'
         53        ROPE_END                                      5  ~37     ~38, !6
         54        ECHO                                                     ~37
   19    55      > JMP                                                      ->61
   22    56    >   ROPE_INIT                                     4  ~42     'PASS%3A+%27'
         57        ROPE_ADD                                      1  ~42     ~42, !4
         58        ROPE_ADD                                      2  ~42     ~42, '%27+was+expected+'
         59        ROPE_END                                      3  ~41     ~42, !5
         60        ECHO                                                     ~41
   24    61    >   ECHO                                                     '%0A'
   16    62      > JMP                                                      ->36
         63    >   FE_FREE                                                  $28
   39    64      > 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 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/RH6r3
function name:  contains
number of ops:  27
compiled vars:  !0 = $str, !1 = $bads, !2 = $template, !3 = $a, !4 = $regex, !5 = $x, !6 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   31     2        ASSIGN                                                   !2, '%2F%28%5Cs%2B%251%24s%5Cs%2B%7C%5E%5Cs%2A%251%24s%5Cs%2B%7C%5Cs%2B%251%24s%5Cs%2A%24%7C%5E%5Cs%2A%251%24s%5Cs%2A%24%29%2F'
   32     3      > FE_RESET_R                                       $8      !1, ->24
          4    > > FE_FETCH_R                                               $8, !3, ->24
   33     5    >   INIT_FCALL                                               'sprintf'
          6        SEND_VAR                                                 !2
          7        INIT_FCALL                                               'preg_quote'
          8        SEND_VAR                                                 !3
          9        SEND_VAL                                                 '%2F'
         10        DO_ICALL                                         $9      
         11        SEND_VAR                                                 $9
         12        DO_ICALL                                         $10     
         13        ASSIGN                                                   !4, $10
   34    14        INIT_FCALL                                               'preg_match'
         15        SEND_VAR                                                 !4
         16        SEND_VAR                                                 !0
         17        SEND_REF                                                 !6
         18        DO_ICALL                                         $12     
         19        ASSIGN                                           ~13     !5, $12
         20      > JMPZ                                                     ~13, ->23
   35    21    >   FE_FREE                                                  $8
         22      > RETURN                                                   <true>
   32    23    > > JMP                                                      ->4
         24    >   FE_FREE                                                  $8
   38    25      > RETURN                                                   <false>
   39    26*     > RETURN                                                   null

End of function contains

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.41 ms | 1013 KiB | 16 Q