RE: Restore Leading Zeros in Zip Codes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx] 
> Sent: Thursday, August 21, 2008 8:08 PM
> To: 'Keith Spiller'; php-general@xxxxxxxxxxxxx
> Subject: RE:  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@xxxxxxxxxxxx]
> > Sent: Thursday, August 21, 2008 7:44 PM
> > To: php-general@xxxxxxxxxxxxx
> > Subject:  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
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux