PHP htmlentities() 未按预期工作

发布于 2024-12-20 06:44:46 字数 331 浏览 9 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是年少的欢喜 2024-12-27 06:44:46

您必须设置 htmlentities() 的第三个参数,它告诉要使用的字符集。因为你没有设置它,所以使用默认值,默认是ISO-8859-1,而不是UTF-8。

与 htmlspecialchars() 一样,它采用可选的第三个参数 charset,用于定义转换中使用的字符集。目前,默认使用 ISO-8859-1 字符集。

只是为了澄清,这是函数签名:

string htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $charset [, bool $double_encode = true ]]] )

在这里您可以找到官方文档: 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.

Like htmlspecialchars(), it takes an optional third argument charset which defines character set used in conversion. Presently, the ISO-8859-1 character set is used as the default.

Just to clarify, this is the function signature:

string htmlentities ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $charset [, bool $double_encode = true ]]] )

and here you'll find the official doc: http://php.net/manual/en/function.htmlentities.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文