The solution should be to filter out the HTML to make sure it's OK:
- Valid HTML
- These are only the tags you want to allow.
- And does not cause any security problems.
A great tool that does this is HTMLPurifier (citation):
HTML Cleaner is a standard compatible PHP filter library written in PHP. The HTML cleaner will not only remove all malicious code (better known as XSS) with a thoroughly tested, reliable whitelist, it will also make sure your documents are compliant
Basically, after the HTML has been entered by the user, before you save it in your database, you must pass it through an HTML cleaner, which will make sure that it is valid and remove the tag / attribute that you did not specify as "allowed" .
source share