-
Notifications
You must be signed in to change notification settings - Fork 186
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
Save as html instead of xml. Fixes self-closing tags and utf-8 encoding. #154
Conversation
$document = new \DOMDocument('1.0', 'UTF-8'); | ||
$internalErrors = libxml_use_internal_errors(true); | ||
$document->loadHTML($html); | ||
$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why converting the encoding here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
This solves the issues with self-closing tags (<br> going to <br></br>) and assists with utf-8 encoding.
@techi602 Good point, I've added in both of your tests (they both passed). |
👍 |
@tijsverkoyen |
@josh18 Why is the HTML5 doctype converted to lowercase? See also http://stackoverflow.com/questions/7020961/uppercase-or-lowercase-doctype |
You are right, either is fine. If I remember correctly DOMDocument always converts it to uppercase so I converted it to lowercase so that it matches the user put in lowercase. Of course this means it won't match if the user starts with uppercase but it seems like lowercase is more of the "standard" for html5, for example HTML5Boilerplate. |
This solves the issues with self-closing tags (
<br>
going to<br></br>
) and assists with utf-8 encoding.@techi602 I think this should solve all the utf-8 encoding issues?