|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-01-30 10:38 UTC] johannes@php.net
-Status: Open
+Status: Not a bug
[2013-01-30 10:38 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 01:00:01 2025 UTC |
Description: ------------ I found this error while trying to parse an ordered list. When I access the firstChild or the lastChild of a DOM object that is in turn derived from another DOM object , the value is printed perfectly. However, when I try to access childDomObject->childNodes->item(0), the code fails. Test script: --------------- <?php $html_data = '<html><body> <ol> <li><strong>Question 1</strong> Answer1</li> <li><strong>Question 2</strong> Answer2</li> </ol> </body></html>'; $doc = new DOMDocument(); $doc->loadHTML($html_data); $xpath = new DOMXPath($doc); $ols = $xpath->query('//ol'); $ol = $ols->item(0); $lis = $ol->childNodes; foreach ($lis as $li) { //echo $li->firstChild->nodeValue."<br />"; //echo $li->lastChild->nodeValue."<br />"; echo $li->childNodes->item(0)->nodeValue."<br />"; } Expected result: ---------------- Question 1 Answer1<br /> Question 2 Answer2<br /> Actual result: -------------- Question 1<br />