" has two childNodes? "/>

DOMDocument thinks "" has two childNodes?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm trying to mess around with PHP5's DOM functions and have run into
something that confuses me:

$dom = new DOMDocument();

echo $dom->childNodes->length;

Why is the output 2?  Shouldn't it be 1?

Re: DOMDocument thinks "" has two childNodes?

Quoted text here. Click to load it

$dom = new DOMDocument();

print get_class($dom->childNodes->item(0)) . "<br>";
print get_class($dom->childNodes->item(1)) . "<br>";

print htmlspecialchars($dom->saveHTML());

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd "> <html></html>  

Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Site Timeline