- print_r: documentation ( source)
- str_replace: documentation ( source)
- trim: documentation ( source)
- preg_split: documentation ( source)
<?php
function splitStreetNameNumber($str) {
$str = trim($str);
if (0 >= strlen($str)) {
return false;
}
$t = preg_split('/[0-9]+/', $str);
$num = str_replace($t[0], '', $str);
return array(
'name' => trim($t[0]),
'num' => trim($num),
);
}
$a = array(
'Karlstr. 2',
'Karl Straße 2d',
'Karlsplatz 14 a',
'Karlsplatz',
);
foreach($a as $b) {
$c = splitStreetNameNumber($b);
print_r($c);
}