Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从HTML字符串解析时间_Php_Regex - Fatal编程技术网

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>";
?>