UTF-8 French accented characters issue

ぃ、小莉子 提交于 2019-12-30 09:37:22

问题


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?


回答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.




回答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?



来源:https://stackoverflow.com/questions/16123076/utf-8-french-accented-characters-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!