PHP htmlentities() 未按预期工作
我在 htmlentities() 方面遇到问题
$txt = "árbol";
echo $txt; // outputs: árbol
echo htmlentities($txt); // outputs: árbol (árbol)
第二个 echo 应输出 árbol (á)
我正在使用 utf-8:
<meta charset="utf-8">
发生了什么事?谢谢你!
I'm having a problem with htmlentities()
$txt = "árbol";
echo $txt; // outputs: árbol
echo htmlentities($txt); // outputs: árbol (árbol)
The second echo should output árbol (á)
I'm using utf-8:
<meta charset="utf-8">
What's going on? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须设置 htmlentities() 的第三个参数,它告诉要使用的字符集。因为你没有设置它,所以使用默认值,默认是ISO-8859-1,而不是UTF-8。
只是为了澄清,这是函数签名:
在这里您可以找到官方文档: http ://php.net/manual/en/function.htmlentities.php
You have to set the third parameter of
htmlentities()
which tells the charset to use. Because of you don't set it, the default is used and the default is ISO-8859-1, not UTF-8.Just to clarify, this is the function signature:
and here you'll find the official doc: http://php.net/manual/en/function.htmlentities.php