Reputation: 41
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
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