更新时间:2023-09-18 12:08:16
找到了一个很好的答案:
Found a great answer for this one:
使用PHP 5并使用DOMDocument对象的loadHTML()方法。这自动解析格式错误的HTML,随后调用saveXML()将输出有效的HTML。 DOM函数可以在这里找到:
Use PHP 5 and use the loadHTML() method of the DOMDocument object. This auto parses badly formed HTML and a subsequent call to saveXML() will output the valid HTML. The DOM functions can be found here:
使用此:
$doc = new DOMDocument();
$doc->loadHTML($yourText);
$yourText = $doc->saveHTML();