Last active
April 4, 2023 14:17
-
-
Save R0B3RDV/e94c46c44a603e02afa2d226c6ef6367 to your computer and use it in GitHub Desktop.
Function in PHP to split Dutch addresses as a string, to an array with street, number and addition apart
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
<?php | |
function split_street(string $streetStr) :array { | |
$aMatch = array(); | |
$pattern = '#^([\w[:punct:] ]+) (\d{1,5})\s?([\w[:punct:]\-/]*)$#'; | |
preg_match($pattern, $streetStr, $aMatch); | |
$street = $aMatch[1] ?? $streetStr; | |
$number = $aMatch[2] ?? ''; | |
$numberAddition = $aMatch[3] ?? ''; | |
return array('street' => $street, 'number' => $number, 'numberAddition' => $numberAddition); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try the pattern as unicode:
$pattern = '/^([\w[:punct:] ]+) (\d{1,5})\s?([\w[:punct:]\-\/]*)$/u';