PHP strtotime()is a useful function that can convert a string representation of time to a unix timestamp. From this, we can convert time to any format we like.
However, the original temporary lines are not in a format that strtotime()can handle directly. eg. "h" should be "hour". But we could replace them before going to strtotime () if your data is consistent.
Note that we are trying to convert the original time to 0, not the current time.
$rawTimes = array ('42 sec', '1 min', '2 h 32min');
foreach ($rawTimes as $rawTime) {
$rawTime = str_replace('h','hour',$rawTime);
echo '"'.$rawTime.'" = "'.gmdate('H:i:s',strtotime($rawTime,0)).'"'."\n";
}
:
"42 sec" = "00:00:42"
"1 min" = "00:01:00"
"2 hour 32min" = "02:32:00"
, strtotime() "", "", "", "" "". , , , . "32 " "32 " .