I have a submit field that may have an address formatted like:
1234 main st
or may just be the street name: main
I need to split the number off if present so I can test against database fields.
I need a eregi, split or preg_split that could do that. I've tried a few and either get the whole string in the first array element, or it fails to see the digits.
if(eregi('[:digits:]+',$streetSearch,$streetArray)) die("num: $streetArray[0] name=$streetArray[1]");
if(eregi('([\d]+) (.+)',$streetSearch,$streetArray)) die("num: $streetArray[0] name=$streetArray[1]");
list($streetNum,$streetName)=split('(\d+) ',$streetSearch);die($streetNum);
$streetArray=preg_split('/^(\d+) (.+)/',$streetSearch);
die("street number: $streetArray[0] street name:$streetArray[1]");
any help would be appreciated.
Terry
Why use a split?
preg_match('/(\d*)(.*?)/', $streetString, $matches); $streetNumber = $matches[1]; $streetRemainder = $matches[2]; //maybe use trim()?
-- -- paperCrane <Justin Patrin>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php