Created
March 31, 2010 14:36
-
-
Save benvds/350404 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @brief Splits an address string containing a street, number and number addition | |
* | |
* @param $streetStr string An address string containing a street, number (optional) and number addition (optional) | |
* | |
* @return array Data array with the following keys: street, number and numberAddition. | |
*/ | |
private function split_street($streetStr) { | |
$aMatch = array(); | |
$pattern = '#^([\w[:punct:] ]+) ([0-9]{1,5})([\w[:punct:]\-/]*)$#'; | |
$matchResult = preg_match($pattern, $streetStr, $aMatch); | |
$street = (isset($aMatch[1])) ? $aMatch[1] : ''; | |
$number = (isset($aMatch[2])) ? $aMatch[2] : ''; | |
$numberAddition = (isset($aMatch[3])) ? $aMatch[3] : ''; | |
return array('street' => $street, 'number' => $number, 'numberAddition' => $numberAddition); | |
} | |
private function test_split_street() { | |
$testStreets = array(); | |
$testStreets[] = "laan 1933 2"; | |
$testStreets[] = "18 septemberplein 12"; | |
$testStreets[] = "kerkstraat 42-f3"; | |
$testStreets[] = "Kerk straat 2b"; | |
$testStreets[] = "1, rue de l'eglise"; // jammer-de-bammer | |
$testStreets[] = "42nd street, 1337a"; | |
$testStreets[] = "1e constantijn huigensstraat 1b"; | |
$testStreets[] = "Heuvel, 2a"; | |
$testStreets[] = "Heuvel 13"; | |
$testStreets[] = "3-koningenstraat, 21 13b"; // jammer-de-bammer | |
$testStreets[] = "glaslaan 2, gebouw SWA 71"; | |
for ($i = 0, $totalTestStreets = count($testStreets); $i < $totalTestStreets; $i++) { | |
$address = $this->split_street($testStreets[$i]); | |
debug($testStreets[$i]); | |
debug($address['street']); | |
debug($address['number']); | |
debug($address['numberAddition']); | |
} | |
} |
hi, i've created a simplified version of this one, with some minor bug fixes, maybe it can help someone with further development. https://gist.github.com/R0B3RDV/e94c46c44a603e02afa2d226c6ef6367
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created a repo on PHP for this matter, see: https://github.com/WebRTB/address-splitter. it is still w.i.p. though pull requests are more then welcome.