前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PHP html_entity_decode()函数讲解

PHP html_entity_decode()函数讲解

作者头像
砸漏
发布2020-10-21 10:05:53
9120
发布2020-10-21 10:05:53
举报
文章被收录于专栏:恩蓝脚本恩蓝脚本

PHP html_entity_decode() 函数

实例

把 HTML 实体转换为字符:

<?php 
$str = "&lt;&copy; W3CS&ccedil;h&deg;&deg;&brvbar;&sect;&gt;"; 
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 &amp; '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 &Oslash;yvind &Aring;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.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档