fill string with a character.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aetoc
Forum Commoner
Posts: 37
Joined: Tue Jan 31, 2006 2:48 am

fill string with a character.

Post by aetoc »

I have a string with a one or two digit number and I want to fill it with zeros. Can someone remind me how I do it.

Example:

12 -> 0012, 3 -> 0003


Thanks in advance,
Aetoc
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: fill string with a character.

Post by WebbieDave »

Code: Select all

str_pad($num, 4, '0', STR_PAD_LEFT);
aetoc
Forum Commoner
Posts: 37
Joined: Tue Jan 31, 2006 2:48 am

Re: fill string with a character.

Post by aetoc »

Thanks. You save me :D

:crazy: :banghead: :dubious:
Post Reply