Php 从HTML字符串解析时间
有人能帮我从这个代码中获取小时、分钟、秒吗:Php 从HTML字符串解析时间,php,regex,Php,Regex,有人能帮我从这个代码中获取小时、分钟、秒吗: <strong class="countdown"> 23:16:27</strong> 如何用正则表达式或其他东西解析这个倒计时计时器,并将其转换为$hour、$minutes、$seconds?(对不起我的英语)使用strotime();见: $r=sscanf($str、%f、%f、$hour、$minutes、$secundes);strtotime()对此不起作用吗?$str=$x
<strong class="countdown"> 23:16:27</strong>
如何用正则表达式或其他东西解析这个倒计时计时器,并将其转换为$hour、$minutes、$seconds?(对不起我的英语)使用strotime();见:
$r=sscanf($str、%f、%f、$hour、$minutes、$secundes);strtotime()对此不起作用吗?$str=$xpath2->query(“//strong[@class='countdown']”->item(0)->textContent);
$r = sscanf($str, "%f,%f,%f", $hour, $minutes, $secundes);
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];
}
<?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>";
?>