php 一切都在 UTF8 上,但我仍然有奇怪的字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31382524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:25:10  来源:igfitidea点击:

All is on UTF8 but I still got strange char like ?

phpmysqlutf-8character-encoding

提问by lio

My database is "utf8_general_ci", tables & columns are also "utf8_general_ci". Php file is also saved in UT8, I got the header in UTF8, so ... everything is UTF8.

我的数据库是“utf8_general_ci”,表和列也是“utf8_general_ci”。Php文件也保存在UT8中,我得到了UTF8的标题,所以......一切都是UTF8。

But I still got that ? char when there is accents.

但我还是明白了?有重音时的字符。

I checked with iconv and it is UTF8. I also tested the encoding with mb_detect_encoding and the result is the same UTF8.

我用 iconv 检查过,它是 UTF8。我还用 mb_detect_encoding 测试了编码,结果是相同的 UTF8。

This drive me crazy ...

这让我发疯...

I got one thing to work : utf8_encode($string) this give me "Actualité" instead of "Actualit?s"

我要做一件事:utf8_encode($string) 这给我“Actualité”而不是“Actualit?s”

Is it possible this has been double-utf8 encoded ?

这可能是双 utf8 编码的吗?

How can I fix this ?

我怎样才能解决这个问题 ?

回答by lio

Ok, I finally make it work. Thanks Mark Baker. Here is the solution I used.

好的,我终于让它工作了。谢谢马克贝克。这是我使用的解决方案。

I just added this to my PDO layer :

我刚刚将它添加到我的 PDO 层:

$dbh = new PDO('mysql:charset=utf8mb4');

There are also 2 other ways to do it, read further here : UTF-8 all the way through

还有其他两种方法可以做到这一点,请在此处进一步阅读:UTF-8 all way through