It will only add the zero if it's less than the required number of characters.

Edit: As pointed out by @FelipeAls:

When working with numbers, you should use %d (rather than %s), especially when there is the potential for negative numbers. If you're only using positive numbers, either option works fine.

You can use sprintf: http://php.net/manual/en/function.sprintf.php

It will only add the zero if it's less than the required number of characters.

Edit: As pointed out by @FelipeAls:When working with numbers, you should use

`%d`

(rather than`%s`

), especially when there is the potential for negative numbers. If you're only using positive numbers, either option works fine.For example:

`sprintf("%04s", 10);`

returns 0010`sprintf("%04s", -10);`

returns 0-10Where as:

`sprintf("%04d", 10);`

returns 0010`sprintf("%04d", -10);`

returns -010