30

我将如何去“零填充”一个整数?

IE

1 becomes 0001
40 becomes 0040
174 becomes 0174
4

2 回答 2

79
$filled_int = sprintf("%04d", $your_int)
于 2009-09-18T10:05:58.913 回答
22
$number = 12;
$width = 4;
$padded = str_pad((string)$number, $width, "0", STR_PAD_LEFT); 
于 2009-09-18T10:05:37.713 回答