Function for converting 3 to 00003?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hyaku
Forum Newbie
Posts: 4
Joined: Tue Sep 12, 2006 12:10 pm

Function for converting 3 to 00003?

Post by Hyaku »

Hi!
Is there a function for PHP to convert 3 to 00003, for example if I:

Code: Select all

echo some_function(3);

The result would be 00003! I need to save data to spreadsheet, but it needs to have thous 00 in the left. I could just add "00" to these vaiables, but the problem is it can be also 5234, so it would have to be 05234. Any suggestions? Thank you!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Code: Select all

str_pad()
Hyaku
Forum Newbie
Posts: 4
Joined: Tue Sep 12, 2006 12:10 pm

Post by Hyaku »

Thank you very much!! By the way, nice post count (666) :twisted:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sprintf() would generally be my choice for this.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Hello Feyd, rather than jus follow blindly (I am fully aware how good you are 8O ) can you give a reason why... Is it qucker or something.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I haven't tested them against each other. It's from my C days. Old habits and all. ;)
Post Reply