Home >Backend Development >PHP Tutorial >这段代码错哪了DOMDOCUMENT

这段代码错哪了DOMDOCUMENT

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:43:541020browse

这段代码哪里错了DOMDOCUMENT
如果换成previousSibling的话就正常的

<br />$doc = new DOMDocument();<br />$html = <<<HTML<br /><html><br /><body><br /><ul id="list"><br /><li>Foo</li><br /><li>Bar</li><br /></ul><br /><br /><h2 class = 'test'>heading3</h2><br /><br /><h3>heading3</h3><br /><br /><ul id="list2"><br /><li>list2</li><br /><li>list2</li><br /></ul><br /><br /></body><br /></html><br />HTML;<br /><br /><br />$doc ->loadHTML($html);<br /><br />$ul = $doc->getElementsByTagName('*');<br /><br />foreach($ul as $node) {<br />     if ($node -> hasAttribute('class')) {<br /><br />           foreach($node -> nextSibling ->childNodes as $morenodes) {<br /><br />               print_r($morenodes);<br />               }<br />    }<br />  }<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn