Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PHP: Fix broken html tags in string and use html entities
* Fix for broken html tags inside strings for php.
* By using passing the html through DOMDocument and converting the html
* entities we are left with beautiful well formatted code. Huzzah!
* "Nothing is ever easy" -Zedd, Wizards First Rule
* @var DOMDocument
$doc = new DOMDocument();
$doc->substituteEntities = false;
$content = mb_convert_encoding($sValue, 'html-entities', 'utf-8');
$sValue = $doc->saveHTML();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.