Una pagina PHP riceve alcune stringhe da un modulo. Le riceve correttamente (e fin qui, tutto bene). Il problema è che l'utente che le ha scritte può aver aggiunto qualche apostrofo (ad esempio, per scrivere "l'uomo"). Allora PHP aggiunge i caratteri di escape, e la stringa diventa "l\'uomo". Quello che vorrei fare è togliere il backslash e, al posto dell'apice mettere la stringa "’", che è l'apostrofo. Ho scritto ua funzione, ma ho problemi. La funzione, che ho riportato qui sotto, "ottimizza" la stringa, sostituendo anche tutte le lettere accentate.
Codice PHP:
function perfeziona_testo ($testo){
$testo = ereg_replace ("à", "à", $testo);
$testo = ereg_replace ("è", "è", $testo);
$testo = ereg_replace ("ì", "ì", $testo);
$testo = ereg_replace ("ò", "ò", $testo);
$testo = ereg_replace ("ù", "ù", $testo);
$testo = ereg_replace ("À", "À", $testo);
$testo = ereg_replace ("È", "È", $testo);
$testo = ereg_replace ("Ì", "Ì", $testo);
$testo = ereg_replace ("Ò", "Ò", $testo);
$testo = ereg_replace ("Ù", "Ù", $testo);
$testo = ereg_replace ("é", "é", $testo);
$testo = ereg_replace ("É", "É", $testo);
$testo = ereg_replace ("\n", "<br>", $testo);
$testo = ereg_replace ("'", "’", $testo);
$testo = ereg_replace ("\\"."’", "’", $testo);
return $testo;
}
Non riesco a togliere i backslash e ogni volta che ci provo dà errore oppure li tiene e non fa niente. Ho già fatto una ricerca sul forum e non ho trovato nulla. Qualcuno ha qualche idea/suggerimento?