Re: Restore Leading Zeros in Zip Codes
| From: | Philip Thompson | Date: | Mon, 25 Aug 2008 12:39:59 +0000 |
| Subject: | Re: Restore Leading Zeros in Zip Codes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278652@lists.php.net to get a copy of this message | ||
On Aug 21, 2008, at 9:44 PM, Keith Spiller wrote:
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 $len = strlen ($zip); if ($len < 5) {
str_pad ($zip, 5, 0, STR_PAD_LEFT);} else if ($len < 9) {
str_pad ($zip, 9, 0, STR_PAD_LEFT);} ?> Of course as others have mentioned, if you need to account for '-', then modify appropriately. ~Philip