Mysql utf32_unicode_ci 和 html 字符集使用 utf-8,但出现字符

2021-12-27 00:00:00 encoding mysql html

我在 MySQL 字段中有一些法语文本,在 PHPMyAdmin 下正确显示:

I have some text in French in a MySQL field, which appears correctly under PHPMyAdmin:

mentionné

该字段被编码为 utf32_unicode_ci.(它是一个 varchar(500), utf32_unicode_ci).

The field is encoded as utf32_unicode_ci. (It is a varchar(500), utf32_unicode_ci).

但是调用 PHP 脚本调用此参数并以 utf-8 编码的 html 输出返回:

but a call to a PHP script calling this parameter and outputing in html encoded in utf-8 returns:

mentionn�

这是我的 php html 标题的摘录:

Here is an extract of my php html header:

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="fr-FR">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

我该如何解决这个问题?

How can I fix this?

推荐答案

除了数据库编码之外,请务必检查以下内容:

Please, besides the database encoding, be sure you check the following:

  • 文件的 utf8 编码 (js/php)(在超级编辑下,F12:另存为 UTF8-NOBOM)
  • utf8 html 内容:
  • 你的数据库连接的utf8:SET character_set_connection = 'utf8'
  • 查询结果的utf8:SET character_set_results = 'utf8'
  • 你的数据库客户端的utf8:SET character_set_client = 'utf8'
  • 你的mysql表的utf8:ALTER TABLE table CONVERT TO CHARACTER SET utf8;
  • 您的数据库服务器的 utf8:SET character_set_database = 'utf8'SET character_set_server = 'utf8'
  • 在某些情况下,当硬编码值需要编码时,需要在文件中强制使用 utf8.例如,您需要在文件顶部添加注释,使用 charset=utf-8,以便超编辑或您喜欢的编辑器可以检测到它.
  • utf8 encoding of the FILES (js/php) (under ultra-edit, F12: save as UTF8-NOBOM)
  • utf8 html content: <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
  • utf8 of your db connection: SET character_set_connection = 'utf8'
  • utf8 of your query results: SET character_set_results = 'utf8'
  • utf8 of your db client: SET character_set_client = 'utf8'
  • utf8 of your mysql tables: ALTER TABLE table CONVERT TO CHARACTER SET utf8;
  • utf8 of your db server: SET character_set_database = 'utf8' and SET character_set_server = 'utf8'
  • in some cases, forcing utf8 in file is necessary when hardcoded values need encoding. You would need to add a comment on top of your file for instance, with charset=utf-8, so ultra edit or your favorite editor can detect it.

rgds.

ps:我不知道 utf32 但不知何故逻辑应该是一样的

ps: I don't know utf32 but somehow the logic should be the same

相关文章