自动关闭打开的html标记

Auto close an open html tag

本文关键字:html 标记      更新时间:2023-09-26

我创建了一个博客网站,每个拥有帐户的人都可以在这里创建自己的博客。新的博客文章将保存在MYSQL数据库中。我的问题是,如果用户忘记关闭HTML标记,整个网站就会显示错误。

示例:

<p><b>This is Bold</p>
<p>This must be displayed normal</p>

如何使用Javascript或PHP修复此问题?

这就是我修复的方法

$content = "<p><b>This is Bold</p>'n<p>This must be displayed normal</p>";
$doc = new DOMDocument();
@$doc->loadHTML($content);
$content = $doc->saveHTML(); // corrected html