Skip to content

Instantly share code, notes, and snippets.

@mllvzeth
Created April 6, 2017 20:58
Show Gist options
  • Save mllvzeth/8108b6507eb09a2e849bb07c3bf84131 to your computer and use it in GitHub Desktop.
Save mllvzeth/8108b6507eb09a2e849bb07c3bf84131 to your computer and use it in GitHub Desktop.
load HTML as UTF-8 using simple hack:
<?php
/**
* @mdmitry at gmail dot com
*
*/
$doc = new DOMDocument();
$doc->loadHTML('<?xml encoding="UTF-8">' . $html);
// dirty fix
foreach ($doc->childNodes as $item)
if ($item->nodeType == XML_PI_NODE)
$doc->removeChild($item); // remove hack
$doc->encoding = 'UTF-8'; // insert proper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment