我使用此功能来完成HTML。
function correct_html($string) {
$dom = new \DOMDocument;
$dom->loadHTML($string);
$mock = new \DOMDocument;
$body = $dom->getElementsByTagName('body')->item(0);
foreach ($body->childNodes as $child) {
$mock->appendChild($mock->importNode($child, true));
}
return trim($mock->saveHTML());
}
但是当我将此功能与é或任何其他特殊字符一起使用时,它会给我é。我该如何解决
答案 0 :(得分:0)
我认为您应该在DOMDocument的结构中添加编码。
createYg() {
return this._fb.group({
subfield: '',
Z: this._fb.array([])
});
}
createZg() {
return this._fb.group({
subsubfield: ''
});
}
还要确保在标题中设置了编码。
$dom = new DOMDocument('1.0', 'UTF-8');
答案 1 :(得分:0)
尝试添加
utf8_decode()
像这样将字符串解析为loadHTML()之前,
function correct_html($string) {
$dom = new \DOMDocument();
$dom->loadHTML(utf8_decode($string));
$mock = new \DOMDocument;
$body = $dom->getElementsByTagName('body')->item(0);
foreach ($body->childNodes as $child) {
$mock->appendChild($mock->importNode($child, true));
}
return trim($mock->saveHTML());
}