I used HTML Purifier to allow users to enter only special, safe, HTML comments in text fields. This is a very good job and has very good documentation.
For everything else, like a simple text field or a selection window, when I write a value to a page, I always run it through htmlentities():
htmlentities ($_POST['email'], ENT_QUOTES);
As long as all user data is always written to the page using htmlentities(), you should never have a problem with XSS.
source
share