What is wrong with this code? DOMDOCUMENT

Source: Internet
Author: User
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 = <<


  • Foo

  • Bar



heading3

heading3


  • list2

  • list2





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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.