redgenieuk Posted January 11 Share Posted January 11 Morning! I have started using DOMdocument for a job but hit an issue with this code snippet. if ($txtnode1->parentNode->hasChildNodes()) { Echo "***Has Children Start***<br>"; foreach ($txt1->parentNode as $child) { Echo "NodeChild<br>"; } Echo "***Has Children End***<br>"; } I get the output: ***Has Children Start*** ***Has Children End*** So ($txtnode1->parentNode->hasChildNodes()) is true; But foreach ($txtnode1->parentNode as $child) Isn't looping.... I think indicating there are no children? But there must be a child.... because we are going to $txtnode1's parentNode... so in summary i am very confused! Any help greatly appreciated. TIA. Quote Link to comment https://forums.phpfreaks.com/topic/317621-domdocument-haschildnodes-but-foreach-not-showing-children/ Share on other sites More sharing options...
Solution redgenieuk Posted January 11 Author Solution Share Posted January 11 Stupidity has been found. I am answering my own question as I cannot see how to remove it; but hopefully it might help someone else one day! Answer is: foreach ($txtnode1->parentNode as $child) should be foreach ($txtnode1->parentNode->childNodes as $child) Quote Link to comment https://forums.phpfreaks.com/topic/317621-domdocument-haschildnodes-but-foreach-not-showing-children/#findComment-1614079 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.