日期:2014-05-16 浏览次数:20535 次
$doc = new DOMDocument();
$html = <<<HTML
<html>
<body>
<ul id="list">
<li>Foo</li>
<li>Bar</li>
</ul>
<h2 class = 'test'>heading3</h2>
<h3>heading3</h3>
<ul id="list2">
<li>list2</li>
<li>list2</li>
</ul>
</body>
</html>
HTML;
$doc ->loadHTML($html);
$ul = $doc->getElementsByTagName('*');
foreach($ul as $node) {
if ($node -> hasAttribute('class')) {
foreach($node -> nextSibling ->childNodes as $morenodes) {
print_r($morenodes);
}
}
}