468,769 Members | 2,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,769 developers. It's quick & easy.

DOMDocument thinks "<html></html>" has two childNodes?

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

<?php
$dom = new DOMDocument();
$dom->loadHTML('<html></html>');

echo $dom->childNodes->length;
?>

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

Dec 1 '06 #1
1 2027
On 1 Dec 2006 14:37:11 -0800, "yawnmoth" <te*******@yahoo.comwrote:
>I'm trying to mess around with PHP5's DOM functions and have run into
something that confuses me:

<?php
$dom = new DOMDocument();
$dom->loadHTML('<html></html>');

echo $dom->childNodes->length;
?>

Why is the output 2? Shouldn't it be 1?
<?php
$dom = new DOMDocument();
$dom->loadHTML('<html></html>');

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

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

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

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Donald Firesmith | last post: by
7 posts views Thread by Diandian Zhang | last post: by
4 posts views Thread by Don Wash | last post: by
36 posts views Thread by Roedy Green | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.