将尾随零添加到字符串

How can I add some trailing zeros to a string like in following example:

$number= sprintf("%04s", "02");
echo $number;

This displays 0002 but I want 0200

If you don't know how long your original input will be and you want the padding to be flexible (I assume that is what you need...), you can set the padding to the other side like this:

$number= sprintf("%-04s", "02");
                   ^ here
echo $number;

Have a look at http://php.net/manual/en/function.str-pad.php

$number= str_pad("02", 4, 0);
echo $number;

You could use str_pad:

str_pad('02', 4, '0');