skip to Main Content
Add Zero Before US Zipcode/Pincode

Add Zero before US Zipcode/Pincode

Many times US zipcode/Pincode starting with zero ( 00501, 00503 ), I am working on a project on that Many users do not enter the full Zipcode, User entering only ( 501, 503 ) without Zero. I am using that Zipcode/Pincode for fetching the User location lat lang using Google Geolocation API. For, Fetching proper location form Google API I should pass valid Zipcode/Pincode with zero. Let’s see the easiest solution for add Zero before US Zipcode/Pincode.

Add ZERO before Zipcode/Pincode

print str_pad('501', 5, 0, STR_PAD_LEFT);  // Output : 00501

Add ZERO after Zipcode/Pincode

print str_pad('501', 5, 0, STR_PAD_RIGHT); // Output : 50100

The easiest way to adding the ZERO before Zipcode/Pincode using “str_pad” function.

Saroj

I am a web designer and developer part-time blogger. Write something on some free time. Find my every day thought here :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top