简体   繁体   English

UTF-8法语重音字符问题

[英]UTF-8 French accented characters issue

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: 当我使用phpmyadmin看到存储在mysql数据库中的数据时,字符的存储方式与éàç一样,但是当我使用php在具有以下结构的html文档上显示这些数据时:

<!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. 我得到了方形而不是重音字符,但是,我没有在静态内容上的任何重音字符没有这个问题,这些字符还没有从同一页面中的mysql加载。

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: mysql原始数据的一部分:

éçà

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 ! 结果我得到一个固定的mysql,静态与正方形!

any hints? 任何提示?

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): 这是非常常见的字符集问题,您需要手动为MySQL连接设置连接编码(这些应该是您在建立连接后执行的第一个查询):

SET NAMES utf8;
SET CHARACTER SET utf8;

And also make sure every table has CHARACTER SET set to UTF-8 . 并确保每个表都将CHARACTER SET设置为UTF-8

Or you could also update server configuration . 或者您也可以更新服务器配置

Looks like a misconfiguration issue. 看起来像是一个配置错误的问题。 Most probably your DB or drivers are not using UTF-8. 很可能你的数据库或驱动程序没有使用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. 当您更改为windows-1552时,来自数据库的数据显示OK,而静态文件不能表示您的源文件(正确)为UTF-8,但数据库中的数据到达编码格式错误。

Whatever is going on, stick to UTF-8. 无论发生什么,坚持使用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? 在my.cnf中将MySQL默认字符集更改为UTF-8?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM