I am working with a membership database which records all accounts in a six digit format however, some users will be using a sub-six digit format due to older conventions. So I want to be able to accept a sub-six digit number and prefix zeroes to the beginning of it.
e.g. user enters number 1234, I want PHP to format it to become 001234. user enters number 123, I want PHP to format it to become 000123.
You can use PHPs sprintf()-function:
$formattedNumber = sprintf('%06d', $unformattedNumber);
Too Easy
str_pad($input, 6, "0", STR_PAD_LEFT);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With