htmlentities 和 é (e 急性)
我对 PHP 的 htmlentities
和 é 字符有疑问。我知道这是我忽略的某种编码问题,所以希望有人能看到我做错了什么。
直接运行 htmlentities("é")
不会按预期返回正确的代码(é
或 é
我尝试强制字符集为“UTF-8”(使用 htmlentities 的字符集参数),但
最终目标是在 HTML 电子邮件中编码发送该字符 。 “ISO-8859-1”。当我尝试将其强制转换为该编码时,您会在电子邮件的源代码中看到 é,并在 HTML 视图中看到 é
。对我的错误有一些了解吗?
I'm having a problem with PHP's htmlentities
and the é character. I know it's some sort of encoding issue I'm just overlooking, so hopefully someone can see what I'm doing wrong.
Running a straight htmlentities("é")
does not return the correct code as expected (either é
or é
. I've tried forced the charset to be 'UTF-8' (using the charset parameter of htmlentities) but the same thing.
The ultimate goal is to have this character sent in an HTML email encoded in 'ISO-8859-1'. When I try to force it into that encoding, same issue. In the source of the email, you see é, and in the HTML view é
.
Who can shed some light on my mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我添加了 htmlspecialchars 供您查看它是否真正编码
http://sandbox.phpcode.eu/ g/11ce7/4
I have added htmlspecialchars for you to see that it is really encoded
http://sandbox.phpcode.eu/g/11ce7/4
我建议您查看 http://php.net/html_entity_decode 。您可以通过以下方式使用它:
这样您就不必关心 php 文件的编码。
编辑:错别字
I suggest you take a look at http://php.net/html_entity_decode . You can use this in the following way:
This way you don't have to care about the encoding of the php file.
edit: typo
我修复了
I fixed with
如果您将特殊字符存储为 é,那么您可以在连接到数据库后立即使用以下内容。
这样,您现在在显示数据时就不需要使用
htmlentities
了。If you have stored the special characters as é, then you could use the following soon after making connection to the
database
.With this, you now don't need to use
htmlentities
while displaying data.