php remove invalid chars

狂风中的少年 提交于 2019-12-12 12:01:53

问题


I have the following errors outputed when I work with $dom->loadHTML('<?xml version="1.0" encoding="UTF-8"?>' . $html);.

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Char 0xD860 out of allowed range in Entity, line: 1 in D:\xampp\xampp\htdocs\xampp\similarity\functions.php on line 438
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Char 0xDEE2 out of allowed range in Entity, line: 1 in D:\xampp\xampp\htdocs\xampp\similarity\functions.php on line 438
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Invalid char in CDATA 0x3 in Entity, line: 1 in D:\xampp\xampp\htdocs\xampp\similarity\functions.php on line 438

How do I target and remove those "invalid" charaters using php?

Andrej


回答1:


not tested, but this should work:

$buffer = ob_get_clean();
$tidy = new tidy();
$myHTML = $tidy->repairString('<?xml version="1.0" encoding="UTF-8"?>' . $html);

$dom->loadHTML($myHTML);


来源:https://stackoverflow.com/questions/10512857/php-remove-invalid-chars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!