WordPress 编码问题

发布于 2024-10-15 20:25:01 字数 623 浏览 2 评论 0原文

我遇到的问题似乎与 WordPress 有关,但也可能是其他问题。

发生的事情是这样的:

我有一个博客,其中的帖子使用 utf-8 字符(简单的字符,如 ')。当前所有字符都显示正确,但是我正在将站点移动到另一台服务器,并发现所有 utf-8 字符都有问题(“变成”)。

我一开始以为是MySQL的问题,但是查了一下好像不是这样的。我通过与 Navicat 同步创建了新数据库,并确认数据库和所有表都是 utf-8。当在我尝试过的任何 SQL 程序(Sequel Pro、Navicat)中查看任一数据库中的数据时,字符显示为未编码 (’)。我尝试过各种同步方法,包括其他人所说的解决编码问题的方法,但它们对我不起作用。

对我来说证实这一点的是设置一个测试 php 脚本,该脚本从每个数据库中提取一个 post_content 字段。在测试脚本中,字符显示编码('),无论它们来自哪个数据库。

我检查了 apache 配置文件,发现两个系统上的 HTTP_ACCEPT_CHARSET 设置为相同的(ISO-8859-1,utf-8;q=0.7,*;q=0.7)。

Soooo,我认为这是一个 WordPress 问题,尽管我当然可能是错的。

任何帮助将不胜感激,我已经为此烦恼了一段时间了;)

谢谢。

I'm having what seems to be a problem related to WordPress, though it could be something else.

Here's what's happening:

I have a blog with posts using utf-8 characters (simple ones like ’). The characters all display correctly currently, however I'm moving my site to another server and seeing problems with all the utf-8 chars (’ becomes ’).

I first thought the problem was with MySQL, but after looking into it it seems not to be the case. I created the new database by doing a synch with Navicat, and have confirmed that both db's and all tables are utf-8. When viewing the data in either db in any SQL program I've tried (Sequel Pro, Navicat) the chars show up unencoded (’). I've tried various synching methods, including ones that others have said solved encoding problems, but they did not work for me.

What confirmed it for me, was setting up a test php script which pulled a single post_content field from each database. In the test script the chars show up encoded (’) regardless of which db they come from.

I checked the apache config file and found that HTTP_ACCEPT_CHARSET is set to the same (ISO-8859-1,utf-8;q=0.7,*;q=0.7) on both systems.

Soooo, I'm left thinking that it's a WordPress issue, though of course I could be wrong.

Any help would be truly appreciated, I’ve been banging my head on this for awhile now ;)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怕倦 2024-10-22 20:25:01

您所看到的是 UTF-8 数据被解释为 ISO-8859-1(或 Win-1252,或其他单字节编码)。像这样的问题几乎总是发送到浏览器的标头与实际编码之间不匹配。有些东西告诉浏览器该流是 ISO-8859-1,而实际上发送的是 UTF-8。

What you are seeing is UTF-8 data being interpreted as if it were ISO-8859-1 (or Win-1252, or another single-byte encoding). Problems like this are almost always a mismatch between the headers being sent to the browser and the actual encoding. Something is telling the browser that the stream is ISO-8859-1 while actually sending UTF-8.

灯下孤影 2024-10-22 20:25:01

所以最后我还是用了一个插件来解决这个问题。以下是我采取的步骤:

  1. 使用 Navicat for MySQL 将旧数据库的结构和内容迁移到新数据库(尽管我认为任何复制方法都可以)。
  2. 使用 ALTER TABLE 'wp_posts' CHANGE COLUMN 'post_content' 'post_content' longtext CHARACTER SET utf8 NOT NULL after 'post_date_gmt'; 将 wp_posts 表中的列的编码更改为 utf8;
  3. 使用 ISO 到 UTF 内容插件 将表中的任何非编码字符转换为utf 字符。

So, I've finally ended up using a plug-in to solve the problem. Here are the steps I took:

  1. Migrate the structure and content of the old database to the new database using Navicat for MySQL (though I think any method of copying will work).
  2. Change the encoding of the columns in the wp_posts table to utf8 using ALTER TABLE 'wp_posts' CHANGE COLUMN 'post_content' 'post_content' longtext CHARACTER SET utf8 NOT NULL after 'post_date_gmt';
  3. Use the ISO to UTF content plug in to convert any non-encoded chars innthe table to utf chars.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文