I came across this html utility. The code uses a white list of tags that are allowed for input. The script then formats the input text and removes tags and scripts that can be used to attack using cross-site scripting.
For your purposes, you cannot have any tags in the white list.
Html utilty
source
share