WordPress 编码问题
我遇到的问题似乎与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所看到的是 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.
所以最后我还是用了一个插件来解决这个问题。以下是我采取的步骤:
ALTER TABLE 'wp_posts' CHANGE COLUMN 'post_content' 'post_content' longtext CHARACTER SET utf8 NOT NULL after 'post_date_gmt'; 将 wp_posts 表中的列的编码更改为 utf8;
So, I've finally ended up using a plug-in to solve the problem. Here are the steps I took:
ALTER TABLE 'wp_posts' CHANGE COLUMN 'post_content' 'post_content' longtext CHARACTER SET utf8 NOT NULL after 'post_date_gmt';