This should be very easy, but I am not getting it. I wish to receive hours:minutes, and return hours:minutes:seconds in 00:00:00 format. The following falls way short. Recommendations on the best way to do this? Thank you
<?php
function fixTime($t)
{
$a = explode(':', trim($t));
return ((count($a)==2) && ($h=$a[0]) && ($m=$a[1]) && ($h>=0) && ($m>=0) && ($h<=23) && ($m<=59))?$h.':'.$m.':00':'00:00:00';
}
echo(fixTime('23:33').'<br />');
echo(fixTime('05:00').'<br />');
echo(fixTime('5:00').'<br />');
?>
The strtotime function will help you out here:
Also, see the date function for a list of formatting options available.
To validate such simple input, a regular expression might be helpful: