I\'m trying to parse an html file.
The idea is to fetch the span\'s with title
and desc
classes and to fetch their information in each div that
Make the queries relative... start them with a dot (e.g. ".//…"
).
foreach ($arts as $art) {
// Note: single slash (direct child)
$titles = $xpath->query("./span[@class='title']", $art);
if ($titles->length > 0) {
$title = $titles->item(0)->nodeValue;
echo $title;
}
$descs = $xpath->query("./span[@class='desc']", $art);
if ($descs->length > 0) {
$desc = $descs->item(0)->nodeValue;
echo $desc;
}
}