PHP htmlentities() not working as expected(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() 没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP htmlentities() 没有按预期工作
基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
