PHP htmlentities() 没有按预期工作 [英] PHP htmlentities() not working as expected

查看:38
本文介绍了PHP htmlentities() 没有按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 htmlentities() 时遇到问题

I'm having a problem with htmlentities()

$txt = "árbol";
echo $txt; // outputs: árbol
echo htmlentities($txt); // outputs: árbol (árbol)

第二个回声应该输出 árbol (á)

我使用的是 utf-8:

I'm using utf-8:

<meta charset="utf-8">

这是怎么回事?谢谢!

推荐答案

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

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.

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

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 ]]] )

在这里你会找到官方文档:http://php.net/手册/en/function.htmlentities.php

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

这篇关于PHP htmlentities() 没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆