[thelist] PHP: display leading zero

Steve Cook sck at biljettpoolen.se
Thu Oct 5 02:12:01 CDT 2000


sprintf should do what you want.
http://www.php.net/manual/function.sprintf.php


You're looking for - sprintf("%02d", $your_string); // to format a string

- or to print directly printf("%02d", $your_string); // notice printf
instead of sprintf!

Hope that helps.

.steve

----------------------------------
   WapWarp - http://wapwarp.com
 Wap-Dev - http://www.wap-dev.net
 Cookstour - http://cookstour.org
----------------------------------


> -----Original Message-----
> From: Lauri Väin [mailto:optima at hot.ee]
> Sent: den 4 oktober 2000 20:52
> To: thelist at lists.evolt.org
> Subject: [thelist] PHP: display leading zero
> 
> 
> Hello everybody, 
> Originally sent this to hwg-languages at hwg.org, but got no responses. 
> 
> <SNIP>
> I'd like to list the numbers 01-31 to a drop down list(select box).
> The code I'm using:
> 
> //////////////////////// snip
> <SELECT name="kuup2ev">
> 
> <OPTION value="<?$kuup2ev = 01; echo $kuup2ev;?>" selected>
> <?echo $kuup2ev;?>
> </OPTION>
> <? $date_select = $kuup2ev;  while($date_select < 32) { ?>
> <OPTION value="<?echo $date_select; ?>"><?echo 
> $date_select;?></OPTION>
> <? $date_select++; } ?>
> 
> </SELECT>
> //////////////////////// snip
> 
> Now, instead of:
> 01
> 02
> 03
> 04
> ...
> 
> I get:
> 1
> 2
> 3
> 4
> ...
> 
> The question: How can I make PHP display the leading zero in 
> case the number is
> only one digit?
> 
> </SNIP>
> 
> Thanks,
> Lauri
> 
> 
> 
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt ! 
> 




More information about the thelist mailing list