从长字符串中获取价值

时间:2017-07-22 02:55:06

标签: php

下面有一个HTML字符串。

<?php $str="<td class="team_info" align="center" height="26"><strong>Match Time:<script language="Javascript" type="text/javascript">formatDate('2017,6,11,23,30,00',1)</script>7/12/2017&nbsp;06:30&nbsp;Wednesday &nbsp;&nbsp; </strong></td>"
?>

我想获得字符串'2017,6,11,23,30,00'并将每个数字放入数组中。请帮忙 。谢谢朋友们。

1 个答案:

答案 0 :(得分:0)

使用以下代码:

$str="<td class=\"team_info\" align=\"center\" height=\"26\"><strong>Match Time:<script language=\"Javascript\" type=\"text/javascript\">formatDate('2017,6,11,23,30,00',1)</script>7/12/2017&nbsp;06:30&nbsp;Wednesday &nbsp;&nbsp; </strong></td>";

preg_match("/'([0-9,\s]+)'/", $str, $matches);
if(count($matches) > 1) {
    print_r(explode(',', $matches[1]));
}