prova anche con:

htmlentities()
htmlspecialchars()

mi pare sia tutto descritto in entrambe le pillole citate.