Frage

Ho can I get the data-time value from the following code with xpath->query in php

<span class="timestamp" data-time="1395846963">33m</span>
War es hilfreich?

Lösung

Try this, using DOMDocument and 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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top