原:$currentStr =<abbr class="timeago" title="2015-12-27 22:32:02 +0800">22:32</abbr>
目标: 2015-12-27 22:32:02
代码:
$before = "class=\"timeago\" title=\"";
$end = " \+0800\">";
$pattern = "/".$before."(.*)".$end."/U";//匹配指定字符开头,指定字符结尾。
preg_match_all($pattern, $currentStr, $matches_current);
$time = $matches_current[1][0];
before和end写上你的开头和结尾字符串,记得特殊字符要用\转义。
preg_match_all 运行一下,然后var_dump()结果,就能看懂这个命令的输出了
本文介绍了一种使用PHP正则表达式从特定格式的HTML时间标签中提取时间戳的方法。通过定义开始和结束模式,可以精确地匹配并提取出时间信息。
679

被折叠的 条评论
为什么被折叠?



