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? Link to comment https://forums.phpfreaks.com/topic/76651-solved-left-padding-0s/ 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 Link to comment https://forums.phpfreaks.com/topic/76651-solved-left-padding-0s/#findComment-388092 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 Link to comment https://forums.phpfreaks.com/topic/76651-solved-left-padding-0s/#findComment-388146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.