non capisco, hai provato a dare un occhio al codice generato?

potresti provare anche con :

htmlspecialchars($testo, ENT_QUOTES);

ciao