UTF-8 French accented characters issue

24,165

Solution 1

This is quite common charset issue, you need to set connection encoding manually for MySQL connection (those should be first queries you execute after establishing connection):

SET NAMES utf8;
SET CHARACTER SET utf8;

And also make sure every table has CHARACTER SET set to UTF-8.

Or you could also update server configuration.

Solution 2

Looks like a misconfiguration issue. Most probably your DB or drivers are not using UTF-8.

The fact that the data that comes from the DB shows OK when you change to windows-1552 and the static files do not can mean that your source file is (correctly) in UTF-8, but the data from your DB is arriving in the wrong encoding format.

Whatever is going on, stick to UTF-8.

UPDATE: There is a thread that explains how to automatically set the encoding for the connection:

Change MySQL default character set to UTF-8 in my.cnf?

Share:
24,165
Mbarry
Author by

Mbarry

A web developer since 2002 CV en ligne

Updated on April 22, 2020

Comments

  • Mbarry
    Mbarry about 4 years

    When i see data as stored on mysql database using phpmyadmin, the characters are stored exactly as é à ç however when i use php to display these data on an html document that has the exact following structure:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    </head>
    
    <body>
    </body>
    </html>
    

    I got square instead of accented character, however, i don't have this issue with any accented characters on static content that haven't been loaded from mysql in the same page.

    when i see on the source code of the page they seem to be identical! for example:

    part of static data on the source code displayed as:

    éçà
    

    part of mysql origin data:

    éçà
    

    i tried replacing

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

    with

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

    and as result i got mysql one fixed, static with squares !

    any hints?