我的网页遇到编码问题,这让我发疯。让我尝试解释一下
- 我有一个将 utf8 定义为字符集的元标记。
- 我也将脚本包含为 utf8 (
)。
- 在 .php 中文件,我声明
header('Content-Type: text/html; charset=utf8');
- 在我的数据库 (postgreSQL) 中,我进行了查询
show lc_collate;
> 并且返回为 en_US.UTF-8
- 我正在使用 AJAX
- 当我尝试将字段值“name”保存为“áéíóú”时,我在记录集(使用 phpPgAdmin 查看结果)。
有办法在不使用解码/编码的情况下修复它吗?
谢谢大家!
I'm having encoding problems in my webpage, and it is driving me crazy. Let me try to explain
- I have a meta tag defining utf8 as charset.
- I'm including the scripts as utf8 too (
<script type="text/javascript src="..." charset="utf8"></script>
).
- In .php files, I declare
header('Content-Type: text/html; charset=utf8');
- In my database (postgreSQL), I've made the query
show lc_collate;
and the return was en_US.UTF-8
- I'm using AJAX
- When I try to save the field value "name" as "áéíóú", I get the value "áéÃóú" in the record set (using phpPgAdmin to view results).
What am I doing wrong? There's a way to fix it without using decode/encode? Someone have a good reference about theses issues?
Thank you all!
发布评论
评论(3)
也许客户端编码设置不正确? PostgreSQL 会自动在客户端上的字符编码和数据库中的编码之间进行转换。为此,它需要知道客户端正在使用什么编码。最安全的方法是在打开连接时使用以下命令进行设置:
SET CLIENT_ENCODING TO 'UTF8';
有关详细信息请参阅文档
Maybe the client encoding is not set correctly? PostgreSQL automatically converts between the character encoding on the client and the encoding in the database. For this to work it needs to know what encoding the client is using. Safest is to set this when you open your connection using:
SET CLIENT_ENCODING TO 'UTF8';
For details see the docs
您可能会将数据存储为 ISO-8859-1?
You might be storing the data as ISO-8859-1?
尝试编码为 Base64 并在另一端解码。
Try enconding to base64 and decoding on the other end.