3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr_postcode_regexes = array( 'uk' => array( // Should match any *valid* UK postcode array('[A-Z]', '[A-Z]?', '[0-9]', '[0-9A-Z]?'), ), 'offshore' => array( // All postcode areas that DPD define as "offshore" array('A', 'B', '3', '[0-8]'), // AB30-38 array('A', 'B', '4', '[1-9]'), // AB41-49 array('A', 'B', '5', '[0-6]'), // AB50-56 array('F', 'K', '1', '[789]'), // FK17-19 array('F', 'K', '2', '[01]'), // FK20-21 array('G', '8', '3'), // G83 array('G', 'Y', '9'), // GY9 array('H', 'S', '[1-9]'), // HS1-9 array('I', 'M', '[0-9]', '[0-9A-Z]?'), // IM array('I', 'M', '[0-9]', '[0-9A-Z]?'), // IV array('K', 'A', '2', '[89]'), // KA27-28 array('K', 'W', '[0-9]', '[0-9]?'), // KW0-99 array('P', 'A', '[2-9]', '[0-9]'), // PA20-99 array('P', 'H', '1', '[5-9]'), // PH15-19 array('P', 'H', '[2-9]', '[0-9]'), // PH20-99 array('T', 'R', '2', '[1-5]'), // TR21-25 array('Z', 'E', '[0-9]', '[0-9A-Z]?'), // ZE ), 'ni' => array( // Northern Ireland array('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. // Pack everything out with \s* because people are idiots and put whitespace in weird places. foreach ($arr_postcode_regexes as $str_id => $arr_parts) { $arr_temp = array(); 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*$'; } 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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/piVbK
function name:  (null)
number of ops:  30
compiled vars:  !0 = $arr_postcode_regexes, !1 = $arr_parts, !2 = $str_id, !3 = $arr_temp, !4 = $arr_part
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   34     1      > FE_RESET_R                                       $6      !0, ->25
          2    > > FE_FETCH_R                                       ~7      $6, !1, ->25
          3    >   ASSIGN                                                   !2, ~7
   35     4        ASSIGN                                                   !3, <array>
   37     5      > FE_RESET_R                                       $10     !1, ->15
          6    > > FE_FETCH_R                                               $10, !4, ->15
   38     7    >   INIT_FCALL                                               'implode'
          8        SEND_VAL                                                 '%5Cs%2A'
          9        SEND_VAR                                                 !4
         10        DO_ICALL                                         $12     
         11        CONCAT                                           ~13     $12, '%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D'
         12        ASSIGN_DIM                                               !3
         13        OP_DATA                                                  ~13
   37    14      > JMP                                                      ->6
         15    >   FE_FREE                                                  $10
   41    16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '%7C'
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $15     
         20        CONCAT                                           ~16     '%5E%5Cs%2A%28', $15
         21        CONCAT                                           ~17     ~16, '%29%5Cs%2A%24'
         22        ASSIGN_DIM                                               !0, !2
         23        OP_DATA                                                  ~17
   34    24      > JMP                                                      ->2
         25    >   FE_FREE                                                  $6
   44    26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.49 ms | 1396 KiB | 17 Q