Skip to content

Instantly share code, notes, and snippets.

@joshmfrankel
Last active September 8, 2023 12:22
Show Gist options
  • Select an option

  • Save joshmfrankel/9e54ac68fd8682a817e2 to your computer and use it in GitHub Desktop.

Select an option

Save joshmfrankel/9e54ac68fd8682a817e2 to your computer and use it in GitHub Desktop.

Revisions

  1. joshmfrankel revised this gist Aug 21, 2014. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions fixBrokenHTMLString.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,13 @@
    /**
    * 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');
  2. joshmfrankel created this gist Aug 21, 2014.
    5 changes: 5 additions & 0 deletions fixBrokenHTMLString.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    $doc = new DOMDocument();
    $doc->substituteEntities = false;
    $content = mb_convert_encoding($sValue, 'html-entities', 'utf-8');
    $doc->loadHTML($content);
    $sValue = $doc->saveHTML();