PHP htmlentities()无法正常工作 [英] PHP htmlentities() not working as expected
问题描述
我遇到htmlentities()有问题
I'm having a problem with htmlentities()
$txt = "árbol";
echo $txt; // outputs: árbol
echo htmlentities($txt); // outputs: árbol (árbol)
应输出árbol(& aacute;)
我正在使用utf-8:
I'm using utf-8:
<meta charset="utf-8">
发生了什么事?谢谢!
推荐答案
您必须设置 htmlentities c>它告诉字符集使用。由于您未设置它,因此使用默认值,默认值为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.
只是为了说明,这是函数签名: / p>
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/manual/en/function.htmlentities.php
and here you'll find the official doc: http://php.net/manual/en/function.htmlentities.php
这篇关于PHP htmlentities()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!