// DOM only for HTML/XML content
if (!
preg_match('/(x|ht)ml/i',
$type,
$xmlMatches)) { return;
} $charset =
preg_match('//u',
$content) ? 'UTF-8' : 'ISO-8859-1';
// http://www.w3.org/TR/encoding/#encodings
// http://www.w3.org/TR/REC-xml/#NT-EncName
$content =
preg_replace_callback('/(charset *= *["\']?)([a-zA-Z\-0-9_:.]+)/i',
function D
$m) use (&
$charset) { if ('charset=' ===
$this->
convertToHtmlEntities('charset=',
$m[2
])) { $charset =
$m[2
];
} return $m[1
].
$charset;
},
$content, 1
);
if ('x' ===
$xmlMatches[1
]) { $this->
addXmlContent($content,
$charset);
} else { $this->
addHtmlContent($content,
$charset);
} }