Forum Moderators: coopster

Message Too Old, No Replies

Splitting Mailing Addresses

         

Ahkamden

5:56 pm on Feb 20, 2010 (gmt 0)

10+ Year Member



Can someone point me in the direction of how to split a single address into parts like taking '123 west ave' into:

$house = '123'
$street = 'west ave'

I'm not familiar with preg_match but thought it might be able to handle this? My other thought was a chunk split, but my problem with that is some addresses may be 123, another 1234, 1234A, etc. So I'm not sure what to do with all of those variations.

penders

12:25 pm on Feb 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can someone point me in the direction of how to split a single address into parts like taking '123 west ave'


Does your address always follow the format 'house street' (ie. house -space- street), or is it more complicated than that with possible town and zip codes?

eg. (Split on the first -space-)
$address = '123 west ave'; 
$splitChar = strpos($address,' ');
$house = substr($address,0,$splitChar);
$street = substr($address,$splitChar+1);


Should work for your example (inc. 1234 or 1234A), but might break at other times?

...My other thought was a chunk split...


You could perhaps explode() [uk2.php.net] the string on the -space- and pull the parts from the resulting array?