[thelist] PHP: display leading zero

Raul Beltran espiritudelvino at hotmail.com
Thu Oct 5 01:55:52 CDT 2000


----- Original Message -----
From: "Lauri Väin" <optima at hot.ee>
> The question: How can I make PHP display the leading zero in case the
number is
> only one digit?

    $d = $timearray['mday'];
   // Day
   echo "<select name='listDays'>";

          for($i=1;$i<=31;$i++){
           echo "<option";
           if($i == $d){
            echo " selected ";
           }
           echo ">" . sprintf("%02d",$i) . "</option>";
          }

   echo "</select>";

The line with the sprintf will do what you want... I did this for a project
and worke fine.




More information about the thelist mailing list