Hey,

I know theres something that does this but I can't remember what its called :S

I have this code that reads out numbers i.e. 1,2,3,4 etc.
But I want it to read out as 01,02,03,04 etc.

<?php
$i=0;	
for($i = 1; $i < 32; $i++) {
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>

Anyone jog my memory?

Thanks.

    I can't seem to get sprintf() to work to what I'm after. Is there not a simpler way?

      Installer wrote:
      $i = str_pad($i, 2, '0', STR_PAD_LEFT);

      Thats perfect, I think str_pad was what I used last time, Thanks.

      Thanks to the other replies aswell, sorry I couldn't get sprintf() working.

        bradgrafelman wrote:

        The correct use of [man]sprintf/man would be:

        sprintf('%02s', $i);

        Cheers for that, I see now that it is actualy easier. They should make it easier to find on the manual or maybe just easier to understand. I tried all the specifiers on their own i.e. %02, I didn't realise you had to use the string specifier as well.

        Thanks!

          Write a Reply...