PHP: documentElemnt->childNodes warning

Posted by jun on Stack Overflow See other posts from Stack Overflow or by jun
Published on 2010-03-24T22:10:03Z Indexed on 2010/03/24 22:13 UTC
Read the original article Hit count: 210

Filed under:
|
$xml = file_get_contents(example.com);

$dom = new DomDocument();
$dom->loadXML($xml);

$items = $dom->documentElement;

foreach($items->childNodes as $item) { 
 $childs = $item->childNodes;
 foreach($childs as $i) {
  echo $i->nodeValue . "<br />";
 }
}

Now I get this warning in every 2nd foreach:

Warning: Invalid argument supplied for foreach() in file_example.php  on line 14

Please help guys. Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about domdocument