I have some text blocks like
John+and+Co-Accountants-Hove-BN31GE-2959519
I need a function to extract the postcode \"BN31GE\". It may happen to not exist
Find below code to extract valid UK postal code. It return array if post code found otherwise empty.
0) {
foreach($getArray as $key=>$val) {
if(preg_match("/^(([A-PR-UW-Z]{1}[A-IK-Y]?)([0-9]?[A-HJKS-UW]?[ABEHMNPRVWXY]?|[0-9]?[0-9]?))\s?([0-9]{1}[ABD-HJLNP-UW-Z]{2})$/i",strtoupper($val),$postcode)) {
$getPostcode = $postcode[0];
}
}
}
print"";
print_r($getPostcode);
?>