Is htmlentities best solution to prevent XSS in PHP? Also I would like to allow simple tags like b, i, a and img. What would be the best solution to implement this? I did consider bbcode but found out if not implemented properly I too will have XSS problem. What should I do? Any good third-party library is welcome.
EDIT:
I just tried HTML Purifier and it failed on this case. Just see this example
For that, I would go for the HTML Purifier, and yes you can specify your whitelist tags there too.
I know there are certain functions in PHP language for that but I would prefer a dedicated solution instead.