Daniel O.
Daniel O.

Reputation: 41

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. My problem is that if the user forgot to close an HTML tag, the whole site is displayed wrong.

Example:

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

How can I fix this with Javascript or PHP?

Upvotes: 0

Views: 261

Answers (1)

Xpleria
Xpleria

Reputation: 5873

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

Upvotes: 1

Related Questions