I have read in my places that to prevent XSS attacks, the best practice is to do first a stripslashes
and then a htmlspecialchars
on the user input. However, in some cases that is not possible, for example when allowing the user some basic markup with a WYSIWYG editor.
Does PHP offer any methods for this, that allow a certain whitelist of basic tags (b, i, u, a, img, ...) but strips them of all their potentially dangerous arguments, as well as escaping all html special chars except for the <
,>
and "
belonging to the set of whitelisted tags & tag arguments?
Or should I just forget about doing that and switch to a different approach like using BBcode for user input with markup?