At 17:17 11.03.2003, Andr� Sannerholt said:
--------------------[snip]--------------------
>If for example
>$variable="Hauptstra�e 15";
>
>$variable_string[0] should be "Hauptstra�e"
>$variable_string[1] should be "15"
>
>So I need a function that recognizes a number and explodes the variable at
>that very position.
>It's important that the thing also works when $variable="Hauptstra�e15";
>without any space. Else it would have been easy to do with the explode
>function...
--------------------[snip]--------------------
try a preg_match like (untested):
if (preg_match('/^\s*([^0-9]*)\s*([0-9].*)\s*$/', $address, $aresult)) {
$address = $aresult[1];
$number = $aresult[2];
}
else {
$address = trim($address);
$number = null;
}
Note that preg_match will return false here if no number is available in
$address. Leading and trailing spaces are trimmed from $address and
$number, either by the regular expression, or by the trim() function in
case of a no-match.
Note also that this will fail for US-style addresses like "9th street",
moving everything in $number, leaving $address empty.
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php