-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning: Dom\HTMLDocument::createFromString(): tree error unexpected-token-in-initial-mode in Entity #16807
Comments
hmmm do not know if that is a bug, i.e. if we are supposed to pass a full valid html doc. But I do not have the full picture so cc @nielsdos. |
The dtd is missing, so the document is actually not standard compliant. |
So then partial HTML documents are not supported? There are use cases where you'd want to parse recursively parts of a document, e.g template partials come to mind as a very common use case. I suppose I can indeed suppress the warning, but that to me indicates that I can't rely on making something that is thought to be wrong design, as that would mean the warning can turn into a fatal error at some point in the future. Either that or I just sort of "hack it" and programmatically add a DTD to a HTML partial if its not present, then remove it before merging it to the larger document. |
Yes it is, via
It won't be a fatal error or exception because suppressing parse errors is something people want to do legitimately. You'll find that a lot of web pages actually violate at least one of the parsing/tokenization rules that HTML defines.
Note that the parser adds a body and html tag implicitly, so you'll have to get rid of that too or use the LIBXML_HTML_NOIMPLIED option. But again, using |
Description
The following code:
Resulted in this output:
But I expected this output instead:
It to work normally, given that it gets a perfectly valid piece of HTML. It doesn't break the HTML parsing, so it seems to work, but for some reason throws a warning.
PHP Version
PHP 8.4.0 RC1
Operating System
Debian 12
The text was updated successfully, but these errors were encountered: