note 95247 added to function.str-pad
| From: | mike at mike-griffiths dot co dot uk | Date: | Mon, 21 Dec 2009 14:00:32 +0000 |
| Subject: | note 95247 added to function.str-pad | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164174@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 82.152.196.90
----
Manual Page -- http://www.php.net/manual/en/function.str-pad.php
Edit -- https://master.php.net/note/edit/95247
Del: integrated -- https://master.php.net/note/delete/95247/integrated
Del: useless -- https://master.php.net/note/delete/95247/useless
Del: bad code -- https://master.php.net/note/delete/95247/bad+code
Del: spam -- https://master.php.net/note/delete/95247/spam
Del: non-english -- https://master.php.net/note/delete/95247/non-english
Del: in docs -- https://master.php.net/note/delete/95247/in+docs
Del: other reasons-- https://master.php.net/note/delete/95247
Reject -- https://master.php.net/note/reject/95247
Search -- https://master.php.net/manage/user-notes.php