note 95247 deleted from function.str-pad by danbrown
| From: | danbrown@php.net | Date: | Mon, 21 Dec 2009 16:59:28 +0000 |
| Subject: | note 95247 deleted from function.str-pad by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164181@lists.php.net to get a copy of this message | ||
Note Submitter: mike at mike-griffiths dot co dot uk
----
This function has a variety of uses. I use it on my blog (http://www.mike-griffiths.co.uk) for
logging specific times. You may want to visit the site for a working example.
<select name="time_hh">
<?php for($i=0; $i<24; $i++): ?>
<option value="<?php echo $i; ?>"><?php echo
str_pad($i,2,'0',STR_PAD_LEFT); ?></option>
<?php endfor; ?>
</select> :
<select name="time_mm">
<?php for($i=0; $i<60; $i++): ?>
<option value="<?php echo $i; ?>"><?php echo
str_pad($i,2,'0',STR_PAD_LEFT); ?></option>
<?php endfor; ?>
</select>
That code will produce two drop-down boxes for the hour and minutes of a day in 24-hour format.
str_pad is used to ensure that there is always a leading zero (if one is needed). A nice little
time saver.