简体   繁体   English

PHP 引号(“„)和其他特殊字符的编码问题

[英]PHP encoding issues with quotes (“„) and other special characters

I've a problem with encoding on german website.我在德国网站上遇到编码问题。 I have a text:我有一个文本:

„Eröffnungsfeier FIS Alpine Ski WM 2011“ „Eröffnungsfeier FIS 高山滑雪 WM 2011“

When this text is saved into database I get?当此文本保存到数据库中时,我得到了什么? instead of those quotes.而不是那些引号。

I've tried placing我试过放置

header("Content-Type: text/html; charset=utf-8");
mb_internal_encoding("UTF-8");
setlocale(LC_ALL, 'de_DE.utf-8');

On the top of the file without success.在文件的顶部没有成功。

When I've used当我用过

mysql_set_charset('utf8', $connect);

But then, when inserting text above after reaching first character like ö the rest of the text is stripped.但是,当到达第一个字符(如 ö)后在上方插入文本时,文本的 rest 将被删除。

The table charset and collation is UTF-8. Script file is saved as UTF-8 without BOM.表字符集和排序规则是 UTF-8。脚本文件保存为 UTF-8,没有 BOM。

I lack of ideas where to look.我不知道去哪里看。

1) Check the schema of your database - are the text fields set up to store utf-8? 1) 检查你的数据库模式 - 文本字段是否设置为存储 utf-8?

2) It sounds like the page posting to this script is not sending UTF-8. Does it have the correct Content-Type header? 2) 听起来发布到此脚本的页面没有发送 UTF-8。它是否具有正确的Content-Type header? What does echo urlencode($var) show? echo urlencode($var)显示什么? (that's a neat hack to see the raw bytes you're getting) (这是一个很好的技巧,可以查看您获得的原始字节)

The things I did helped.我所做的事情有所帮助。 Especially mysql_set_charset('utf8', $connect);特别是mysql_set_charset('utf8', $connect); . . The problem was that there was some unwanted code left by another programmer (utf8_decode).问题是另一个程序员 (utf8_decode) 留下了一些不需要的代码。 Looks like he couldn't deal with utf-8 encoding other way.看起来他无法以其他方式处理 utf-8 编码。

I've also found out that mysql_set_charset('utf8', $connect);我还发现mysql_set_charset('utf8', $connect); is not really needed if you're consistent with the encoding from the beginning.如果您从一开始就与编码保持一致,那么实际上并不需要。

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

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