<?php
$re = '~^(?<address>(?<streetname>\h*\S.*?)\h*(?<housenumber>\d+\h*[A-Za-z]?))(?:/(?<stairs>\d+)(?=(?:/\d+){1,2}))?(?:/(?<floor>\d)(?=(?:/\d+)))?(?:/(?<door>\d+))?$~m';
$strings = [
"Lilienstr. 12a",
"Leibnizstraße 36/28/2",
"Prager Straße 14/3/1/4",
"Guentherstr. 43 B",
"Eberhard-Leibnitz Str. 1/7",
"Schießstätte 7/7"
];
foreach ($strings as $string) {
preg_match_all($re, $string, $matches, PREG_SET_ORDER);
$address = array_filter($matches[0], "is_string", ARRAY_FILTER_USE_KEY);
print_r($address);
}
- Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.13
- Array
(
[address] => Lilienstr. 12a
[streetname] => Lilienstr.
[housenumber] => 12a
)
Array
(
[address] => Leibnizstraße 36
[streetname] => Leibnizstraße
[housenumber] => 36
[stairs] => 28
[floor] =>
[door] => 2
)
Array
(
[address] => Prager Straße 14
[streetname] => Prager Straße
[housenumber] => 14
[stairs] => 3
[floor] => 1
[door] => 4
)
Array
(
[address] => Guentherstr. 43 B
[streetname] => Guentherstr.
[housenumber] => 43 B
)
Array
(
[address] => Eberhard-Leibnitz Str. 1
[streetname] => Eberhard-Leibnitz Str.
[housenumber] => 1
[stairs] =>
[floor] =>
[door] => 7
)
Array
(
[address] => Schießstätte 7
[streetname] => Schießstätte
[housenumber] => 7
[stairs] =>
[floor] =>
[door] => 7
)
preferences:
137.17 ms | 409 KiB | 5 Q