用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > php教程

php html_entity_decode实例教程

时间:2015-01-23  来源:西部数据  作者:西部数据

关于html_entity_decode在大多数情况下是与htmlspecialchars htmlentities配合使用的.

html_entity_decode用法:

string html_entity_decode(string $string [,int $quote_style = ENT_COMPAT [, string $charset ]]).

html_entity_decode() 函数把 HTML 实体转换为字符.

html_entity_decode() 是 htmlentities() 的反函数也html_entity_decode() 是 htmlspecialchars() 的反函数.

  1. $str = "A 'quote' is bold www.phpfensi.com"
  2.  
  3. Outputs: A 'quote' is <b>bold</b> 
  4. $s = htmlspecialchars($str); 
  5.  
  6. echo $s
  7.  
  8. Outputs: A 'quote' is <b>boldwww.111cn.net</b> 
  9.  
  10. echo html_entity_decode($s); 
  11.  
  12. 'quote' is bold 
再看一个实例,代码如下:
  1. $str = "John & 'Adams'"
  2. echo html_entity_decode($str); 
  3. echo ""
  4. echo html_entity_decode($str, ENT_QUOTES); 
  5. echo ""
  6. echo html_entity_decode($str, ENT_NOQUOTES); 
  7. ?>//开源代码phpfensi.com 
  8. //浏览器输出: 
  9. John & 'Adams' 
  10. John & 'Adams' 
  11. John & 'Adams' 

如果在浏览器中查看源代码,会看到这些 HTML:

  1. <html> 
  2. <body> 
  3. John & 'Adams'<br /> 
  4. John & 'Adams'<br /> 
  5. John & 'Adams' 
  6. body> 
  7. html>
来顶一下
返回首页
返回首页
推荐资讯
WiFi太不安全:7岁女孩11分钟内入侵公共网络 WiFi太不安全:7岁女孩11分钟内入侵近期刚刚发布研究说WiFi网络能获得人们手机里多少私人信息,
不服跑个分?人工智能也出现“刷分”乱象 不服跑个分?人工智能也出现“刷分2014年,人工智能领域突然爆发,成为了科研和科技创业的热门
相关文章
    无相关信息
栏目更新
栏目热门