judeddokoinu Posted May 16, 2006 Share Posted May 16, 2006 I'm just looking to trim down my code a bit, if possible.I was wondering if PHP itself had a function that does what this one that I wrote does:[code]function leadzero($number){ if ($number < 10) { $new_number = '0' . $number; return $new_number; } else { return $number; }}[/code] Quote Link to comment Share on other sites More sharing options...
zq29 Posted May 16, 2006 Share Posted May 16, 2006 You might be able to do it with money_format() - But other than that, I don't think there is one. Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted May 16, 2006 Share Posted May 16, 2006 sprintf or printf. in your case[code] $new = sprintf("%02d",$old); [/code]You can do many different kinds of formatting with sprintf or printf.number_format and money_format are also useful functions to consider. Quote Link to comment Share on other sites More sharing options...
trq Posted May 16, 2006 Share Posted May 16, 2006 You might also try [a href=\"http://php.net/strpad\" target=\"_blank\"]strpad[/a](). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.