简体   繁体   English

php-自动关闭打开的html标签

[英]php - Auto close an open html tag

I've created a blog site where everyone with an account can create his own blog. 我创建了一个博客站点,每个拥有帐户的人都可以创建自己的博客。 The new blog post will be saved in a MYSQL database. 新的博客文章将保存在MYSQL数据库中。 My problem is that if the user forgot to close an HTML tag, the whole site is displayed wrong. 我的问题是,如果用户忘记关闭HTML标记,则整个网站将显示错误。

Example: 例:

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

How can I fix this with Javascript or PHP? 如何使用Javascript或PHP修复此问题?

This is how I fixed it 这就是我固定的方式

$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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM