I have a MySQL database with tables in ucs2_slovenian_ci encoding. I would like to write content of tables on utf-8 encoding webpage. So far I tried with:
mysql_set_charset ("utf-8");
mysql_query("SET NAMES 'utf-8'");
...
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
...
<?php echo utf8_encode($text); ?>
...
I’m still geting weird signs (question marks) instead of letters Š,Č,Ž
Nothing seems to work.
Weird thing is that with php command mysql_client_encoding($link) it says I have latin1 encoding. When I look page in Firefox it says UTF-8. What’s wrong?
Please help.
That is not an encoding but a collation. A collation is the information on how something is sorted.
For your website, this isn’t even of interest, because that’s what the database knows about itself – or better: the data stored in itself.
For your website script’s it’s more important that you tell your database which encoding you need – here: UTF-8.
You signal that the database server by specifying the database client encoding. Consult your database client driver manual how to specify that. It could be that:
Take care: it’s
utf8while officially it’s writtenUTF-8. That’s something special with the MySQL database, writeUTF-8asutf8when you set that parameter.Do not use:
because it’s deprecated (not good, see as well the PHP manual and Whether to use “SET NAMES”).
And if you tell the database client which encoding you expect, you don’t need to encode your own, like this:
Remove that stuff, you don’t need it.