class DOMHtml extends DOMDocument function loadHTML html encoding utf-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class DOMHtml extends DOMDocument {
function loadHTML($html, $encoding='utf-8') {
$html = @iconv($encoding, 'UTF-8//TRANSLIT', $html);
$html = preg_replace('/<(script|style|noscript)\b[^>]*>.*?<\/\1\b[^>]*>/is', '', $html);
$tidy = new tidy;
$config = array(
'drop-font-tags' => true,
'drop-proprietary-attributes' => true,
'hide-comments' => true,
'indent' => true,
'logical-emphasis' => true,
'numeric-entities' => true,
'output-xhtml' => true,
'wrap' => 0
);
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
$html = $tidy->value;
$html = preg_replace('#<meta[^>]+>#isu', '', $html);
$html = preg_replace('#<head\b[^>]*>#isu', "<head>\r\n<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />", $html);
return @parent::loadHTML($html);
}
}