fork(1) download
  1. <?php
  2.  
  3. $strs = ["SW1A 1AA", "SW1A", "SW22 3"];
  4. foreach ($strs as $s) {
  5. if (preg_match_all('~[a-zA-Z]+|\d+|[^\da-zA-Z]+~', $s, $chunks)) {
  6. print_r($chunks[0]);
  7. }
  8. }
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
Array
(
    [0] => SW
    [1] => 1
    [2] => A
    [3] =>  
    [4] => 1
    [5] => AA
)
Array
(
    [0] => SW
    [1] => 1
    [2] => A
)
Array
(
    [0] => SW
    [1] => 22
    [2] =>  
    [3] => 3
)