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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawnmoth

    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('<htm l></html>');

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

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

  • Andy Hassall

    #2
    Re: DOMDocument thinks &quot;&lt;html& gt;&lt;/html&gt;&quot; has two childNodes?

    On 1 Dec 2006 14:37:11 -0800, "yawnmoth" <terra1024@yaho o.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('<htm l></html>');
    >
    >echo $dom->childNodes->length;
    >?>
    >
    >Why is the output 2? Shouldn't it be 1?
    <?php
    $dom = new DOMDocument();
    $dom->loadHTML('<htm l></html>');

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

    print htmlspecialchar s($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 :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    Working...