RE: [PHP] Restore Leading Zeros in Zip Codes

From: Date: Fri, 22 Aug 2008 03:08:00 +0000
Subject: RE: [PHP] Restore Leading Zeros in Zip Codes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-278496@lists.php.net to get a copy of this message
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 >

« previous php.general (#278496) next »