$stringa = htmlentities($stringa);

converte tutti i possibili caratteri in entità html...