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() 没有按预期工作
				
        
 
            
        基础教程推荐
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - php中的PDF导出 2022-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				