2

i haven't found the answer at this question browsing around so i guess asking it's ok...

My php code reads from my Mysql Database a string and prints it, here is the code

$sql2=mysql_query("SELECT * FROM Corsi WHERE Nome='$Ln_1[Ln_1]'");
$Ln_1_a = mysql_fetch_array($sql2);
$Ln_1_descr = $Ln_1_a[5];

But special chars, such as 'è' 'à' 'ò' etc. are printed as '�'. My Mysql Encoding is utf8 and also in my html header i have utf8 encoding, so what is wrong with this?

Thanks in advance

4 Answers 4

2

First of all, at the start of your MySQL connection after database selection you should put this query:

mysql_query('SET NAMES utf8');

Then be sure, your page has encoding UTF-8 (I guess you are using HTML, so it should looks like:

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

) and also your script file must be saved in UTF8 encoding.

But I have to remind mysql_* functions are deprecated and you should use mysqli_* or PDO instead with prepared statements due to safety of your queries.

Sign up to request clarification or add additional context in comments.

Comments

1

Try (after mysql_connect) do mysql_query('SET NAMES utf8'). And also check, if font support these characters.

Comments

0

Use the utf8_decode function

like this

$Ln_1_descr = utf8_decode($Ln_1_a[5]);

Comments

0

Use htmlspecialchars($yourvariable, ENT_NOQUOTES, "UTF-8")

Also verify your MySQL configure file has:

[client] default-character-set=UTF-8

[mysql] default-character-set=UTF-8

Also, utf8_encode() and utf8_decode() would work for you as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.