3v4l.org

run code in 500+ PHP versions simultaneously
<?php $keywords = ["key1", "key2"]; $escaped = implode('|', array_map('preg_quote', $keywords)); $pattern = "/\b(?:" . $escaped . ")\b" . ":?(?:\h+|$)|\b(?!(?:" . $escaped . ")\b)[^\s:]+:/"; $strings = [ "aaa bbb key1 ccc", "aaa bbb key1:xxx key2:", "aaa bbb key1: xxx ccc", "aaa bbb key1 :xxx ccc", "aaa bbb xxx:yyy zzz", "aaa bbb ccc", "aaa bbb key1:aaa ccc ddd", "aaa bbb key2:aaa key1:bbb", "aaa bbb aakey1", "aaa bbb key1aa", "aaa bbb key1aa" ]; foreach ($strings as $s) { preg_match_all($pattern, $s, $matches); if (count($matches[0]) > 0) { foreach ($matches[0] as $m) { echo "Invalid string -->'$m' is invalid format, please check it again..." . PHP_EOL; } } else { echo "Valid string --> '$s'" . PHP_EOL; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 42
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 42
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 36
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/MmdrL
function name:  (null)
number of ops:  44
compiled vars:  !0 = $keywords, !1 = $escaped, !2 = $pattern, !3 = $strings, !4 = $s, !5 = $matches, !6 = $m
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    4     1        INIT_FCALL                                                   'array_map'
          2        SEND_VAL                                                     'preg_quote'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $8      
          5        FRAMELESS_ICALL_2                implode             ~9      '%7C', $8
          6        ASSIGN                                                       !1, ~9
    5     7        CONCAT                                               ~11     '%2F%5Cb%28%3F%3A', !1
          8        CONCAT                                               ~12     ~11, '%29%5Cb'
          9        CONCAT                                               ~13     ~12, '%3A%3F%28%3F%3A%5Ch%2B%7C%24%29%7C%5Cb%28%3F%21%28%3F%3A'
         10        CONCAT                                               ~14     ~13, !1
         11        CONCAT                                               ~15     ~14, '%29%5Cb%29%5B%5E%5Cs%3A%5D%2B%3A%2F'
         12        ASSIGN                                                       !2, ~15
    7    13        ASSIGN                                                       !3, <array>
   21    14      > FE_RESET_R                                           $18     !3, ->42
         15    > > FE_FETCH_R                                                   $18, !4, ->42
   22    16    >   INIT_FCALL                                                   'preg_match_all'
         17        SEND_VAR                                                     !2
         18        SEND_VAR                                                     !4
         19        SEND_REF                                                     !5
         20        DO_ICALL                                                     
   23    21        FETCH_DIM_R                                          ~20     !5, 0
         22        COUNT                                                ~21     ~20
         23        IS_SMALLER                                                   0, ~21
         24      > JMPZ                                                         ~22, ->36
   24    25    >   FETCH_DIM_R                                          ~23     !5, 0
         26      > FE_RESET_R                                           $24     ~23, ->34
         27    > > FE_FETCH_R                                                   $24, !6, ->34
   25    28    >   ROPE_INIT                                         3  ~26     'Invalid+string+--%3E%27'
         29        ROPE_ADD                                          1  ~26     ~26, !6
         30        ROPE_END                                          2  ~25     ~26, '%27+is+invalid+format%2C+please+check+it+again...'
         31        CONCAT                                               ~28     ~25, '%0A'
         32        ECHO                                                         ~28
   24    33      > JMP                                                          ->27
         34    >   FE_FREE                                                      $24
   23    35      > JMP                                                          ->41
   28    36    >   ROPE_INIT                                         3  ~30     'Valid+string+--%3E+%27'
         37        ROPE_ADD                                          1  ~30     ~30, !4
         38        ROPE_END                                          2  ~29     ~30, '%27'
         39        CONCAT                                               ~32     ~29, '%0A'
         40        ECHO                                                         ~32
   21    41    > > JMP                                                          ->15
         42    >   FE_FREE                                                      $18
   30    43      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
224.26 ms | 1995 KiB | 15 Q