3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr_postcode_regexes = [ 'uk' => [ // Should match any *valid* UK postcode ['[A-Z]', '[A-Z]?', '[0-9]', '[0-9A-Z]?'], ], 'offshore' => [ ['A', 'B', '3', '[0-8]'], // AB30-38 ['A', 'B', '4', '[1-9]'], // AB41-49 ['A', 'B', '5', '[0-6]'], // AB50-56 ['F', 'K', '1', '[789]'], // FK17-19 ['F', 'K', '2', '[01]'], // FK20-21 ['G', '8', '3'], // G83 ['G', 'Y', '9'], // GY9 ['H', 'S', '[1-9]'], // HS1-9 ['I', 'M', '[0-9]', '[0-9A-Z]?'], // IM ['I', 'M', '[0-9]', '[0-9A-Z]?'], // IV ['K', 'A', '2', '[89]'], // KA27-28 ['K', 'W', '[0-9]', '[0-9]?'], // KW0-99 ['P', 'A', '[2-9]', '[0-9]'], // PA20-99 ['P', 'H', '1', '[5-9]'], // PH15-19 ['P', 'H', '[2-9]', '[0-9]'], // PH20-99 ['T', 'R', '2', '[1-5]'], // TR21-25 ['Z', 'E', '[0-9]', '[0-9A-Z]?'], // ZE ], 'ni' => [ ['B', 'T', '[0-9]', '[0-9A-Z]?'], // ZE ] ]; // Turn the readable-ish map above into actual regexes // It's important that all regexes match only full, valid postcodes, as prefix matching can be ambiguous. foreach ($arr_postcode_regexes as $str_id => $arr_parts) { $arr_temp = []; foreach ($arr_parts as $arr_part) { $arr_temp[] = implode('\s*', $arr_part) . '\s*[0-9]\s*[A-Z]\s*[A-Z]'; } $arr_postcode_regexes[$str_id] = '^\s*(' . implode('|', $arr_temp) . ')\s*$'; } $tests = [ 'M65GQ', 'G83GH', 'G833GH', 'IM14GF', 'TR207HG', 'TR217HG', 'TR21HG', 'BT12HG', ]; foreach ($tests as $test) { echo "$test:\n"; foreach ($arr_postcode_regexes as $name => $expr) { echo " $name: " . (preg_match('/' . $expr . '/i', $test) ? 'yes' : 'no') . "\n"; } echo "\n"; } var_dump($arr_postcode_regexes);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 25
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 15
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 55
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 55
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 52
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 52
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 52
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
Branch analysis from position: 25
filename:       /in/L1HW2
function name:  (null)
number of ops:  60
compiled vars:  !0 = $arr_postcode_regexes, !1 = $arr_parts, !2 = $str_id, !3 = $arr_temp, !4 = $arr_part, !5 = $tests, !6 = $test, !7 = $expr, !8 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   33     1      > FE_RESET_R                                       $10     !0, ->25
          2    > > FE_FETCH_R                                       ~11     $10, !1, ->25
          3    >   ASSIGN                                                   !2, ~11
   34     4        ASSIGN                                                   !3, <array>
   36     5      > FE_RESET_R                                       $14     !1, ->15
          6    > > FE_FETCH_R                                               $14, !4, ->15
   37     7    >   INIT_FCALL                                               'implode'
          8        SEND_VAL                                                 '%5Cs%2A'
          9        SEND_VAR                                                 !4
         10        DO_ICALL                                         $16     
         11        CONCAT                                           ~17     $16, '%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D'
         12        ASSIGN_DIM                                               !3
         13        OP_DATA                                                  ~17
   36    14      > JMP                                                      ->6
         15    >   FE_FREE                                                  $14
   40    16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '%7C'
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $19     
         20        CONCAT                                           ~20     '%5E%5Cs%2A%28', $19
         21        CONCAT                                           ~21     ~20, '%29%5Cs%2A%24'
         22        ASSIGN_DIM                                               !0, !2
         23        OP_DATA                                                  ~21
   33    24      > JMP                                                      ->2
         25    >   FE_FREE                                                  $10
   43    26        ASSIGN                                                   !5, <array>
   54    27      > FE_RESET_R                                       $23     !5, ->55
         28    > > FE_FETCH_R                                               $23, !6, ->55
   55    29    >   NOP                                                      
         30        FAST_CONCAT                                      ~24     !6, '%3A%0A'
         31        ECHO                                                     ~24
   57    32      > FE_RESET_R                                       $25     !0, ->52
         33    > > FE_FETCH_R                                       ~26     $25, !7, ->52
         34    >   ASSIGN                                                   !8, ~26
   58    35        ROPE_INIT                                     3  ~29     '++'
         36        ROPE_ADD                                      1  ~29     ~29, !8
         37        ROPE_END                                      2  ~28     ~29, '%3A+'
         38        INIT_FCALL                                               'preg_match'
         39        CONCAT                                           ~31     '%2F', !7
         40        CONCAT                                           ~32     ~31, '%2Fi'
         41        SEND_VAL                                                 ~32
         42        SEND_VAR                                                 !6
         43        DO_ICALL                                         $33     
         44      > JMPZ                                                     $33, ->47
         45    >   QM_ASSIGN                                        ~34     'yes'
         46      > JMP                                                      ->48
         47    >   QM_ASSIGN                                        ~34     'no'
         48    >   CONCAT                                           ~35     ~28, ~34
         49        CONCAT                                           ~36     ~35, '%0A'
         50        ECHO                                                     ~36
   57    51      > JMP                                                      ->33
         52    >   FE_FREE                                                  $25
   61    53        ECHO                                                     '%0A'
   54    54      > JMP                                                      ->28
         55    >   FE_FREE                                                  $23
   63    56        INIT_FCALL                                               'var_dump'
         57        SEND_VAR                                                 !0
         58        DO_ICALL                                                 
         59      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.04 ms | 1400 KiB | 19 Q