Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-25 Thread Philip Thompson

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

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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-24 Thread ioannes

George Bernard Shaw, an Irishman.

tedd wrote:

At 11:13 PM +0100 8/22/08, Ashley Sheridan wrote:


Not to mention, but of the two major English speaking countries, both 
America and England have different address standards. All too often 
an American site seems to think that a postcode is the same thing as 
a zip code, and then rejects it in a form for being in the wrong format!


Yeah, but that's to be expected.

You Brits get everything wrong -- you drive on the wrong side of the 
street, you eat with your fork in the wrong hand, and your postal 
codes are all messed up.  :-)


As Churchill once said We are two peoples separated by a common 
language.


Cheers,

tedd




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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-24 Thread tedd

At 7:47 PM +0100 8/24/08, ioannes wrote:

George Bernard Shaw, an Irishman.

tedd wrote:



As Churchill once said We are two peoples separated by a common language.



And so did Oscar Wilde, Mark Twain, and Patton -- Google it and 
you'll find that everyone said it.


Cheers,

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-23 Thread tedd

At 11:13 PM +0100 8/22/08, Ashley Sheridan wrote:


Not to mention, but of the two major English speaking countries, 
both America and England have different address standards. All too 
often an American site seems to think that a postcode is the same 
thing as a zip code, and then rejects it in a form for being in the 
wrong format!


Yeah, but that's to be expected.

You Brits get everything wrong -- you drive on the wrong side of the 
street, you eat with your fork in the wrong hand, and your postal 
codes are all messed up.  :-)


As Churchill once said We are two peoples separated by a common language.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-22 Thread tedd

At 8:44 PM -0600 8/21/08, 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


Keith:

Why take them out in the first place? Keep the zip code as a string. 
After all, not all countries use just numbers.


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-22 Thread Afan Pasalic



tedd wrote:

At 8:44 PM -0600 8/21/08, 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


Keith:

Why take them out in the first place? Keep the zip code as a string. 
After all, not all countries use just numbers.


Cheers,

tedd

or, if you use US zip codes only, use ZEROFILL feature in mysql?

-afan



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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-22 Thread Dan Joseph
On Fri, Aug 22, 2008 at 12:28 PM, Afan Pasalic [EMAIL PROTECTED] wrote:



 tedd wrote:

 At 8:44 PM -0600 8/21/08, 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


 Keith:

 Why take them out in the first place? Keep the zip code as a string. After
 all, not all countries use just numbers.

 Cheers,

 tedd

 or, if you use US zip codes only, use ZEROFILL feature in mysql?

 -afan




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


From a recent experience, you should all listen to Tedd's advice.  I
inhereited an application when I came to work at my current job where the
developer used an INT(11) mysql column type for zipcodes.  Its turned things
into a nightmare.  We pulll quotes based off distance and calculate that off
zip codes.  First I found that there are some 4 digit zip codes in other
counties, and shipping from Ohio to New Jersey quotes were coming up as
thousands of miles and thousands of dollars, when they shouldn't have.  Then
there was the announcement of expanding into Canada.  Then came digging thru
all the code trying to redo how zip codes are happening, and ultimately its
lead to a rewrite of the system.

Do yourself a favor, and use a string type, fix the ones you have with a
sprintf() function and be glad you won't have to suffer in the future.

-- 
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.


Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-22 Thread Andrew Ballard
On Fri, Aug 22, 2008 at 12:28 PM, Afan Pasalic [EMAIL PROTECTED] wrote:


 tedd wrote:

 At 8:44 PM -0600 8/21/08, 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

 Keith:

 Why take them out in the first place? Keep the zip code as a string. After
 all, not all countries use just numbers.

 Cheers,

 tedd

 or, if you use US zip codes only, use ZEROFILL feature in mysql?

 -afan

Definitely not. Tedd and Dan are correct; the zeros are significant,
not just filler. Keep in mind that ZIP codes ARE NOT numbers at all,
even if they look like numbers in the US. They are postal codes, which
are a string of character data even if all the characters are numeric
digits. Just expand your database to include Canada and it will become
abundantly clear that a numeric data type is not correct for postal
codes.

Andrew

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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-22 Thread tedd

At 12:35 PM -0400 8/22/08, Dan Joseph wrote:

  tedd wrote:

  Why take them out in the first place? Keep the zip code as a string. After
  all, not all countries use just numbers.


From a recent experience, you should all listen to Tedd's advice.  I
inhereited an application when I came to work at my current job where the
developer used an INT(11) mysql column type for zipcodes.  Its turned things
into a nightmare.  We pulll quotes based off distance and calculate that off
zip codes.  First I found that there are some 4 digit zip codes in other
counties, and shipping from Ohio to New Jersey quotes were coming up as
thousands of miles and thousands of dollars, when they shouldn't have.  Then
there was the announcement of expanding into Canada.  Then came digging thru
all the code trying to redo how zip codes are happening, and ultimately its
lead to a rewrite of the system.

Do yourself a favor, and use a string type, fix the ones you have with a
sprintf() function and be glad you won't have to suffer in the future.

--
-Dan Joseph


Back-side I told the OP to convert to sting, add zeros to the left, 
and left-trim as necessary.


There is much more here than what meets the eye with international addresses.

As a word of caution, don't make anything a number and also open 
address forms to accept multiple strings for international 
addressing. There's a big world out there of people who don't conform 
to what we think is the standard. Remember, if you speak/write 
English then you're only 4 percent of the world's population. We're 
hardly the standard for anything.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-22 Thread Ashley Sheridan
On Fri, 2008-08-22 at 17:16 -0400, tedd wrote:

 At 12:35 PM -0400 8/22/08, Dan Joseph wrote:
tedd wrote:
 
Why take them out in the first place? Keep the zip code as a string. 
  After
all, not all countries use just numbers.
 
 
 From a recent experience, you should all listen to Tedd's advice.  I
 inhereited an application when I came to work at my current job where the
 developer used an INT(11) mysql column type for zipcodes.  Its turned things
 into a nightmare.  We pulll quotes based off distance and calculate that off
 zip codes.  First I found that there are some 4 digit zip codes in other
 counties, and shipping from Ohio to New Jersey quotes were coming up as
 thousands of miles and thousands of dollars, when they shouldn't have.  Then
 there was the announcement of expanding into Canada.  Then came digging thru
 all the code trying to redo how zip codes are happening, and ultimately its
 lead to a rewrite of the system.
 
 Do yourself a favor, and use a string type, fix the ones you have with a
 sprintf() function and be glad you won't have to suffer in the future.
 
 --
 -Dan Joseph
 
 Back-side I told the OP to convert to sting, add zeros to the left, 
 and left-trim as necessary.
 
 There is much more here than what meets the eye with international addresses.
 
 As a word of caution, don't make anything a number and also open 
 address forms to accept multiple strings for international 
 addressing. There's a big world out there of people who don't conform 
 to what we think is the standard. Remember, if you speak/write 
 English then you're only 4 percent of the world's population. We're 
 hardly the standard for anything.
 
 Cheers,
 
 tedd
 
 -- 
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com
 

Not to mention, but of the two major English speaking countries, both
America and England have different address standards. All too often an
American site seems to think that a postcode is the same thing as a zip
code, and then rejects it in a form for being in the wrong format!


Ash
www.ashleysheridan.co.uk


[PHP] Restore Leading Zeros in Zip Codes

2008-08-21 Thread Keith Spiller
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

Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-21 Thread Micah Gersten
if (strlen($zip) == 4 || strlen($zip) == 9)
$zip = 0$zip;

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Restore Leading Zeros in Zip Codes

2008-08-21 Thread Micah Gersten
That's actually not going to work if there's more than 1 zero missing.
This is better.

if (strlen($zip)  5)
$zip = sprintf('%05d',$zip);
else if (strlen($zip)  10)
{
$zipArray = explode('-', $zip);
$zip = sprintf('%05d',$zipArray[0]);
$zip .= - . $zipArray[1];
}
 


Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Micah Gersten wrote:
 if (strlen($zip) == 4 || strlen($zip) == 9)
 $zip = 0$zip;

 Thank you,
 Micah Gersten
 onShore Networks
 Internal Developer
 http://www.onshore.com



 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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Restore Leading Zeros in Zip Codes

2008-08-21 Thread Warren Vail
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:[EMAIL PROTECTED] 
 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



RE: [PHP] Restore Leading Zeros in Zip Codes

2008-08-21 Thread Warren Vail
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:[EMAIL PROTECTED] 
 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:[EMAIL PROTECTED]
  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
 


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



RE: [PHP] Restore Leading Zeros in Zip Codes

2008-08-21 Thread Warren Vail
I never considered the dash a digit, but then I forgot a dollar sign on one
of the variable names, but you can probably figure that out.

Warren Vail 

 -Original Message-
 From: Warren Vail [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, August 21, 2008 8:17 PM
 To: 'Warren Vail'; 'Keith Spiller'; php-general@lists.php.net
 Subject: RE: [PHP] Restore Leading Zeros in Zip Codes
 
 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:[EMAIL PROTECTED]
  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:[EMAIL PROTECTED]
   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
  
 
 
 --
 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