Ninjakreborn Posted November 9, 2007 Share Posted November 9, 2007 If I have a random set of numbers (perhaps some characters). I need to take. $variable = 'whatever'; And pad the variable with 0's up to 10. When it's over with if they variable has below 10 characters, it need's to add zero's up until it has a total of 10 characters. THe 0's need to add on the left hand side, any advice? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 9, 2007 Share Posted November 9, 2007 you'll have to make it a string and use http://uk2.php.net/manual/en/function.str-pad.php Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 9, 2007 Share Posted November 9, 2007 Use the sprintf() function: <?php $str = "4nc9"; $padded_str = sprintf("%010s",$str); echo $padded_str; ?> Ken 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.