r/lolphp•
ealf

DOMDocument assumes the first element it sees is the document element and quietly stuffs all other content inside that.

3v4l.org/kG4sj
3v4l.org

Posted Oct 13, 2016, 12:48 PM UTC

96
the_alias_of_andrea•

Hmm, is that strictly incorrect behaviour? It is using LIBXML_HTML_NOIMPLIED, after all.

If it is incorrect, given it's using libxml (I checked), wouldn't the problem not be with PHP per se?

10
ealfOP•

You're right, it's just a documentation issue. Where it says

Sets HTML_PARSE_NOIMPLIED flag, which turns off the automatic adding of implied html/body... elements.

it should really say

Sets HTML_PARSE_NOIMPLIED flag, which moves arbitrary content inside script tags, because if you wanted an actual HTML parser and not a half-broken XML parser with "HTML" drawn on in crayon, you wouldn't be using PHP.

4†
the_alias_of_andrea•

My guess is a DOM document needs a root element, so if it can't imply HTML tags, it has to use the first element.

10
jspenguin•

Most other "loose" HTML parsers create an <html> element as the root.

4
the_alias_of_andrea•

Right, but here a flag has been used to disable that.

10