By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,446 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.