Last active
April 10, 2020 11:40
-
-
Save mattsandersuk/d40008f533e455d6401a5a488df5b43f to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Split a postcode | |
* @param string $postcode | |
* @return array containing both outer and inner postcodes | |
*/ | |
function split_postcode($postcode) | |
{ | |
// remove spaces to be safe | |
$postcode = str_replace(' ', '', $postcode); | |
// get last 3 characters + trim them | |
$postcodeInner = trim(substr($postcode, -3)); | |
// get remaining characters + trim them to be safe | |
$postcodeOuter = trim(str_replace($postcodeInner, '', $postcode)); | |
// return the split | |
return [ | |
'outer' => str_pad($postcodeOuter, 4, " "), | |
'inner' => str_pad($postcodeInner, 4, " "), | |
]; | |
} |
This file contains 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 | |
/** | |
* Split a postcode | |
* @param string $postcode | |
* @return array containing both outer and inner postcodes | |
*/ | |
function split_postcode($postcode) | |
{ | |
// remove spaces to be safe | |
$postcode = str_replace(' ', '', $postcode); | |
// get last 3 characters + trim them | |
$postcodeInner = trim(substr($postcode, -3)); | |
// get remaining characters + trim them to be safe | |
$postcodeOuter = trim(str_replace($postcodeInner, '', $postcode)); | |
// return the split | |
return [ | |
'outer' => $postcodeOuter, | |
'inner' => $postcodeInner, | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment