Where is the error in this code? if DOMDOCUMENT is replaced with previussibling, $ doc & nbsp; new & nbsp; DOMDocument (); $ html & nbsp; & lt; & lt; HTML & lt; html & gt; & lt; body & gt; & lt; ul & nbsp; & gt; & lt; li & gt; f. where is the error code DOMDOCUMENT?
If you change to previussibling, it will be normal.
$doc = new DOMDocument();
$html = <<
heading3
heading3
HTML;
$doc ->loadHTML($html);
$ul = $doc->getElementsByTagName('*');
foreach($ul as $node) {
if ($node -> hasAttribute('class')) {
foreach($node -> nextSibling ->childNodes as $morenodes) {
print_r($morenodes);
}
}
}
Share: More
------ Solution --------------------
H2's next is h3, h3 has no child
------ Solution --------------------
In this way, should we want to get all ul?
$ Ul = $ doc-> getElementsByTagName ('*');
In this way, all elements are obtained.
Change to $ ul = $ doc-> getElementsByTagName ('Ul ');
In this way, the ul of the page will be obtained ..
In this case, the following loop operation will be okay.