Ciao lore,
se hai tutto in UTF-8, prova a fare così:

Codice PHP:
$str htmlentities(addslashes(utf8_decode(trim($str)))); 
Dovrebbe funzionare.