php 法语口音的字符编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5690023/
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
Character encoding for French Accents
提问by denislexic
I'm developing my first website for a French client and I'm having massive issues with accents being displayed as "?".After googling it for days, I thought I understood, but issues persists.
我正在为一位法国客户开发我的第一个网站,我遇到了大量问题,口音显示为“?”。在谷歌上搜索了几天后,我以为我明白了,但问题仍然存在。
To simplify it, I'll explain just the email headers (the message contains french accents)
为了简化它,我将只解释电子邮件标题(该消息包含法语口音)
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
I've tried using charset UTF-8 and the iso-8859-1, but I still get this type of emails:
我试过使用字符集 UTF-8 和 iso-8859-1,但我仍然收到这种类型的电子邮件:
Merci pour votre int??r?at pour les tee shirts.
Can any one help? I'm having these issues with mySql, HTML, PHP everywhere basically.
任何人都可以帮忙吗?我基本上到处都有 mySql、HTML、PHP 的这些问题。
Thanks.
谢谢。
回答by Artefacto
If intérêt
shows up as int??r?at
you likely (i.e. short of corruption due to double encoding) have UTF-8 encoded text being shown up as if it were ISO-8859-1.
如果intérêt
按照int??r?at
您可能的方式显示(即由于双重编码而没有损坏),则 UTF-8 编码的文本会像 ISO-8859-1 一样显示。
Make sure the headers are correctly formed and present the content as being UTF-8 encoded.
确保标题格式正确,并将内容显示为 UTF-8 编码。
回答by Wilbo Baggins
First of all, make the charset in the header UTF8 again.
首先,再次将标头中的字符集设为 UTF8。
In your page, use utf8_encode()
where appropriate to make sure values coming from a database or external files are properly encoded (try to set the encoding of the fields in your database to UTF8 as well)
在您的页面中,utf8_encode()
在适当的地方使用以确保来自数据库或外部文件的值被正确编码(尝试将数据库中字段的编码也设置为 UTF8)
Also, take a look at the htmlentities()
function to parse special characters to html entities which may solve encoding issues as well.
另外,看看将htmlentities()
特殊字符解析为 html 实体的函数,这也可以解决编码问题。
回答by Dazzle
All other languages except French work fine for me by default
默认情况下,除法语之外的所有其他语言对我来说都很好
In my /fr/messages.php file I was able to resolve this with
在我的 /fr/messages.php 文件中,我能够解决这个问题
'myKey' => utf8_encode('en fran?ais'),