tags:

views:

13

answers:

1

I have to read a txt via file php. This file contains some normal so may contains this kind of symbols :

€ é ò à ° % etc

I read the content in php with file_get_contents and transform these for inserenting in SQL database.

    $contFile = file_get_contents($pathFile);
    $testoCommento = htmlspecialchars($contFile,ENT_QUOTES);
    $testoCommento = addslashes($testoCommento);

Now if I have this text for example : "l'attesa �é cruciale fino a quando il topo non viene morso dall'�€" in the database I have this:

l'attesa è cruciale fino a quando il topo non veniene morso dall'€

When I was GETTING the data from the database I use the php function for decode html entites

$descrizione = htmlspecialchars_decode($risultato['descrizione'],ENT_QUOTES);
$descrizione = addslashes($descrizione);

Now I use jasvascript and AJAX for getting the table content and display to an HTML page In the browser instead of getting the correct text (€,è) I have square symbol. I think there is some mess with charset code/decode but never figured out.

The SQL' table is in "utf8_unicode_ci" format and the column in "utf8_general_ci". The content-type of the page is

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Thanks for help me!

A: 

addslashes() is not Unicode-compatible, you should use a different way to escape the quotes in the strings, or (which would be much better) switch to using prepared statements instead of constructing the SQL query as a string.

You can find more details at: http://eleves.ec-lille.fr/~couprieg/post/Bypass-addslashes-with-UTF-8-characters

m1tk4