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); var_dump(substr('^\s*(A\s*B\s*3\s*[0-8]\s*[0-9]\s*[A-Z]\s*[A-Z]|A\s*B\s*4\s*[1-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|A\s*B\s*5\s*[0-6]\s*[0-9]\s*[A-Z]\s*[A-Z]|F\s*K\s*1\s*[789]\s*[0-9]\s*[A-Z]\s*[A-Z]|F\s*K\s*2\s*[01]\s*[0-9]\s*[A-Z]\s*[A-Z]|G\s*8\s*3\s*[0-9]\s*[A-Z]\s*[A-Z]|G\s*Y\s*9\s*[0-9]\s*[A-Z]\s*[A-Z]|H\s*S\s*[1-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|I\s*M\s*[0-9]\s*[0-9A-Z]?\s*[0-9]\s*[A-Z]\s*[A-Z]|I\s*M\s*[0-9]\s*[0-9A-Z]?\s*[0-9]\s*[A-Z]\s*[A-Z]|K\s*A\s*2\s*[89]\s*[0-9]\s*[A-Z]\s*[A-Z]|K\s*W\s*[0-9]\s*[0-9]?\s*[0-9]\s*[A-Z]\s*[A-Z]|P\s*A\s*[2-9]\s*[0-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|P\s*H\s*1\s*[5-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|P\s*H\s*[2-9]\s*[0-9]\s*[0-9]\s*[A-Z]\s*[A-Z]|T\s*R\s*2\s*[1-5]\s*[0-9]\s*[A-Z]\s*[A-Z]|Z\s*E\s*[0-9]\s*[0-9A-Z]?\s*[0-9]\s*[A-Z]\s*[A-Z])\s*$'), 0, 128);
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/QknVD
function name:  (null)
number of ops:  38
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                                                 
   46    29        INIT_FCALL                                               'var_dump'
         30        INIT_FCALL                                               'substr'
         31        SEND_VAL                                                 '%5E%5Cs%2A%28A%5Cs%2AB%5Cs%2A3%5Cs%2A%5B0-8%5D%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D%7CA%5Cs%2AB%5Cs%2A4%5Cs%2A%5B1-9%5D%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D%7CA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cs%2A1%5Cs%2A%5B5-9%5D%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D%7CP%5Cs%2AH%5Cs%2A%5B2-9%5D%5Cs%2A%5B0-9%5D%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D%7CT%5Cs%2AR%5Cs%2A2%5Cs%2A%5B1-5%5D%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D%7CZ%5Cs%2AE%5Cs%2A%5B0-9%5D%5Cs%2A%5B0-9A-Z%5D%3F%5Cs%2A%5B0-9%5D%5Cs%2A%5BA-Z%5D%5Cs%2A%5BA-Z%5D%29%5Cs%2A%24'
         32        DO_ICALL                                         $19     
         33        SEND_VAR                                                 $19
         34        SEND_VAL                                                 0
         35        SEND_VAL                                                 128
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.33 ms | 1392 KiB | 19 Q