简体   繁体   English

PHP htmlentities()无法正常工作

[英]PHP htmlentities() not working as expected

I'm having a problem with htmlentities() 我在htmlentities()中遇到问题

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

The second echo should output árbol (á) 第二个回显应该输出árbol(á)

I'm using utf-8: 我正在使用utf-8:

<meta charset="utf-8">

What's going on? 这是怎么回事? Thank you! 谢谢!

You have to set the third parameter of htmlentities() which tells the charset to use. 您必须设置htmlentities()的第三个参数,该参数告诉字符集使用。 Because of you don't set it, the default is used and the default is ISO-8859-1, not UTF-8. 由于未设置,因此使用默认值,默认值为ISO-8859-1,而不是UTF-8。

Like htmlspecialchars(), it takes an optional third argument charset which defines character set used in conversion. 像htmlspecialchars()一样,它需要一个可选的第三个参数charset,它定义了转换中使用的字符集。 Presently, the ISO-8859-1 character set is used as the default. 当前,ISO-8859-1字符集被用作默认字符集。

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 在这里您将找到官方文档: http : //php.net/manual/zh/function.htmlentities.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM