Bruno
Bruno

Reputation: 9017

Diacritics from a mysql database not displayed correctly with an HTML and PHP page

I have a mysql database (Wamp) which uses latin1_swedish to encode characters (é, è, ...) but for an unknown reason when I display some results from the database (using an HTML page and a PHP page) the diacritics (à, é, è) are not displayed correctly.

I've already tried to change the charset of my webpage (iso 88599-1, utf-8) but it doesn't work.

Upvotes: 0

Views: 2501

Answers (4)

Bruno
Bruno

Reputation: 9017

echo htmlentities($variable_name);

Upvotes: 2

Nemanja
Nemanja

Reputation: 1535

Did you set your connection to mysql db with the

SET NAMES utf8;

command?

There are several ways:

mysql_query("SET NAMES 'utf8'");

and

mysql_query("SET CHARACTER SET utf8 ");

Or, the "best";

$link = mysql_connect('localhost', 'user', 'password');
mysql_set_charset('utf8',$link);

Upvotes: 0

Pelshoff
Pelshoff

Reputation: 1464

If you know the character encoding that comes in and you know what goes out, you may be able to use iconv: http://www.php.net/manual/en/function.iconv.php

For example if the db is iso-8859 and you need utf-8, you call

iconv("ISO-8859-1", "UTF-8", $text);

You can't just change the character set of a table once values are stored, because the data will not be converted. You will have to convert the data using the available MySQL functions. Read more about that at http://dev.mysql.com/doc/refman/5.0/en/charset-convert.html.

Upvotes: 0

Mathias Bak
Mathias Bak

Reputation: 5115

Try to check the encoding on your files (you can do this with notapad++), in your database (you can see this in phpmyadmin), and your database connection (you can check this in your php file that connects to the db).

They should all match

Upvotes: 0

Related Questions