RE: [PHP] Restore Leading Zeros in Zip Codes
| From: | Warren Vail | Date: | Fri, 22 Aug 2008 03:16:35 +0000 |
| Subject: | RE: [PHP] Restore Leading Zeros in Zip Codes | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278497@lists.php.net to get a copy of this message | ||
Dave brought up something I forgot, what if the "-" is already in the sip
code;
Modify the code as follows;
If(strlen($zipcode) <= 5) $zipcode = sprintf("%05d",$zipcode);
Else {
$zipcode = sprintf("%09d",str_replace("-","",$zipcode));
$zipcode = substr($zipcode,0,5)."-".substr(zipcode,5);
}
> -----Original Message-----
> From: Warren Vail [mailto:warren@vailtech.net]
> Sent: Thursday, August 21, 2008 8:08 PM
> To: 'Keith Spiller'; php-general@lists.php.net
> Subject: RE: [PHP] Restore Leading Zeros in Zip Codes
>
> I'd try something like;
>
> If(strlen($zipcode) <= 5) $zipcode = sprintf("%05d",$zipcode); Else {
> $zipcode = sprintf("%09d",$zipcode);
> $zipcode = substr($zipcode,0,5)."-".substr(zipcode,5);
> }
>
> This isn't real elegant, but it should do the trick. You may
> notice that the 10 character zip code is not 10 digits but
> rather 5 plus 4, or 9 digits.
>
> Warren Vail
>
> > -----Original Message-----
> > From: Keith Spiller [mailto:larentium@hosthive.com]
> > Sent: Thursday, August 21, 2008 7:44 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] Restore Leading Zeros in Zip Codes
> >
> > Hi,
> >
> > RE: Restore Leading Zeros in Zip Codes
> >
> > Does anyone happen to have a script that will restore the leading
> > zeros in a mixed data set of 5 digit zip codes and 10 digit zip+4
> > codes? Any suggestions?
> >
> > Thanks,
> >
> >
> > Keith
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/) To
> unsubscribe, visit: http://www.php.net/unsub.php
>