I would use HTMLPurifier so that you only save HTML
- It's really
- and contains only the tags and attributes that you have selected to allow
I have to add that PHP provides the strip_tags()
function, but this is not so good (quoting):
Because strip_tags()
does not actually check HTML, partially or broken tags can remove more text / data than expected.
This function does not change any attributes in the tags that you allow the use of allowable_tags
, including the style and onmouseover attributes, which an attacker can abuse when publishing text that will be displayed to other users.
source share