如何使用php xpath->查询从span获取数据时间?

时间:2014-03-26 20:23:54

标签: php xpath domxpath

我可以通过php中的xpath->查询从以下代码中获取数据时间值

<span class="timestamp" data-time="1395846963">33m</span>

1 个答案:

答案 0 :(得分:1)

尝试使用DOMDocument和DOMXPath

$str = '<span class="timestamp" data-time="1395846963">33m</span>';

$DOM = new DOMDocument();
$DOM->loadHTML($str);

$XPATH = new DOMXPATH($DOM);

$r = $XPATH->query("//span/@data-time");

var_dump($r->item(0)->nodeValue);