Parsing time from HTML string
Can anyone help me to get hour, minutes, seconds from this code:
<strong class="countdown"> 23:16:27</strong>
I have tried with this code to get data:
$r = sscanf($str, "%f,%f,%f", $hour, $minutes, $secundes);
How to parse this countdown timer with regex or something else, and put into $hour, $minutes, 开发者_Python百科$seconds? (sorry for my English)
Use strtotime(); see here:
<?php
$time = '23:16:27';
$time = strtotime($time);
$hour = date('g',$time);
$minute = date('i',$time);
$second = date('s',$time);
echo "hour: " . $hour . "<br>";
echo "minute: " . $minute . "<br>";
echo "second: " . $second . "<br>";
?>
if (preg_match('/[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}/i', $str, $m)) {
$hours = $m[1];
$minutes = $m[2];
$seconds = $m[3];
}
精彩评论