1

I am getting an error for php domdocument in run time saying

error: "DOMDocument::loadHTML() [<a href='domdocument.loadhtml'>domdocument.loadhtml</a>]: Misplaced DOCTYPE declaration in Entity, DOMDocument::loadHTML() 
line: 1 DOMDocument::loadHTML() [<a href='domdocument.loadhtml'>domdocument.loadhtml</a>]: htmlParseStartTag: misplaced &lt;html&gt; tag in Entity, line2:

My codes

$doc = new DOMDocument();

@$doc->loadHTML($htmlString);

My html string could be varies.

I am not sure how to solve this issue. Can anyone suggest a solution? Thanks so much!

1 Answer 1

4

Well, you should make every effort to try to ensure proper markup. However, you can suppress these errors with:

libxml_use_internal_errors(false);

Which will not trigger errors due to malformed HTML (but you can still access them using libxml_get_errors if you want to see the issues encountered during parsing.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.