Page 1 of 1

Function for converting 3 to 00003?

Posted: Tue Sep 12, 2006 12:17 pm
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!

Posted: Tue Sep 12, 2006 12:28 pm
by jayshields

Code: Select all

str_pad()

Posted: Tue Sep 12, 2006 12:34 pm
by Hyaku
Thank you very much!! By the way, nice post count (666) :twisted:

Posted: Tue Sep 12, 2006 3:17 pm
by feyd
sprintf() would generally be my choice for this.

Posted: Wed Sep 13, 2006 4:20 am
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.

Posted: Wed Sep 13, 2006 5:24 am
by feyd
I haven't tested them against each other. It's from my C days. Old habits and all. ;)