I have to strip all HTML tags and attributes from a user input except the ones considered “safe” (ie, a white list approach).
strip_tags() strips all tags except the ones listed in the $allowable_tags parameter. But I also need to be able to strip all the not whitelisted attributes; for example, I want to allow the <b> tag, but I don’t want to allow the onclick attribute for obvious reasons.
Is there a function to do that, or will I have to make my own?
As far as I know, the
strip_tagssolution is about the fastest way to get rid of unwanted tags, and barring 3rd party packages, checking for allowable attributes would be quite easy in DOMDocument,