Re: Zip to postcode
| From: | William Bailey | Date: | Wed, 02 Apr 2003 12:31:24 +0000 |
| Subject: | Re: Zip to postcode | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-141974@lists.php.net to get a copy of this message | ||
Hi Andy,
The following function seems to work for me:
function split_postcode ($postcode) {
if(eregi('(^[A-Z]{1,2})([0-9|A-Z]{1,2}).*([0-9][A-Z]{2}$)', str_replace('
', '', $postcode), $parts)){
$outcode=strtoupper(sprintf('%s%s%s', $parts[1], @str_repeat(' ',
4-strlen($parts[1])-strlen($parts[2])), $parts[2]));
$incode=strtoupper($parts[3]);
return array($outcode, $incode);
}else{
return False;
}
}
On Wednesday 02 April 2003 12:54, Andy wrote:
> Can someone please tell me how i change the following code:
> if (!ereg("^[0-9]{5,5}(\-[0-9]{4,4})?$",$postcode))
>
> to a UK postcode QQ1 1QQ
> When i fill out the form it tells me that the postcode is not valid and i
> think it is because it is in zip code format.
>
> Thank you
>
> Andy
--
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk