<?php
$doc = new DOMDocument();
$string = '<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="content-type" content="text/html" />
<title>test</title>
</head>
<body>
<div class="List">
<span class="bold">foo</span>
<span class="bold">bar</span>
<span class="bold">base</span>
</div>
</body>
</html>
';
$doc->loadHTML($string);
$xpath = new DOMXpath($doc);
$elements = $xpath->query('//span[@class="bold"]');
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
echo $node->nodeValue. "\n";
}
}
}
?>