io normalmente utilizzo htmlspacialchars($testo, ENT_QUOTES);
guarda se è quello che cerchi