On Tue, Mar 11, 2003 at 05:17:52PM +0100, André Sannerholt wrote: > Hi everyone!
Hi André. > I wondered how to sepearate string variables that contain streetnames and > numbers: > > 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... You probably also want the function to recognize addresses in which the number precedes the street name (Canada, US, Britain, etc). You also want to support multiple-word streetnames, which would not work if you explode using a space as seperator. This is untested: function splitstreetaddress($what) { if (ereg('[^0-9][0-9]+$', $what)) { $temp = ereg_replace('(.*[^0-9])([0-9]+)$','\\1__\\2', $what); list($name, $number)=explode('__', $temp); } else if (ereg('^[0-9]+', $what)) { $temp = ereg_replace('^([0-9]+)(.*)','\\1__\\2', $what); list($number, $name)=explode('__', $temp); } else { $name=$what; $number="" } $retval[0]=trim($name); $retval[1]=trim($number); return $retval; } -- Paul Chvostek <[EMAIL PROTECTED]> Operations / Abuse / Whatever it.canada, hosting and development http://www.it.ca/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php