当前位置: 移动技术网 > IT编程>开发语言>PHP > PHP html_entity_decode()函数讲解

PHP html_entity_decode()函数讲解

2019年05月28日  | 移动技术网IT编程  | 我要评论

php html_entity_decode() 函数

实例

把 html 实体转换为字符:

<?php 
$str = "<© w3csçh°°¦§>"; 
echo html_entity_decode($str); 
?>

上面代码的 html 输出如下(查看源代码):

<!doctype html> 
<html> 
<body> 
<© w3csçh°°¦§> 
</body> 
</html>

上面代码的浏览器输出如下:

<© w3csçh°°¦§>

定义和用法

html_entity_decode() 函数把 html 实体转换为字符。

html_entity_decode() 函数是htmlentities() 函数的反函数。

语法

html_entity_decode( _string,flags,character-se_ t)

实例 1

把一些 html 实体转换为字符:

<?php 
$str = "jane & 'tarzan'"; 
echo html_entity_decode($str, ent_compat); // will only convert double quotes 
echo "<br>"; 
echo html_entity_decode($str, ent_quotes); // converts double and single
quotes 
echo "<br>"; 
echo html_entity_decode($str, ent_noquotes); // does not convert any quotes 
?>

上面代码的 html 输出如下(查看源代码):

<!doctype html> 
<html> 
<body> 
jane & 'tarzan'<br> 
jane & 'tarzan'<br> 
jane & 'tarzan' 
</body> 
</html>

上面代码的浏览器输出如下:

jane & 'tarzan' 
jane & 'tarzan' 
jane & 'tarzan'

实例 2

通过使用西欧字符集,把一些 html 实体转换为字符:

<?php 
$str = "my name is øyvind åsane. i'm norwegian."; 
echo html_entity_decode($str, ent_quotes, "iso-8859-1"); 
?>

the html output of the code above will be (view source):

<!doctype html> 
<html> 
<body> 
my name is øyvind åsane. i'm norwegian. 
</body> 
</html>

上面代码的浏览器输出如下:

my name is øyvind åsane. i'm norwegian.

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对移动技术网的支持。如果你想了解更多相关内容请查看下面相关链接

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网