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