如何删除html特殊字符? [英] How to remove html special chars?

查看:120
本文介绍了如何删除html特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序创建一个RSS feed文件,在其中我想删除HTML标签,这是由strip_tags完成的.但是strip_tags并未删除HTML特殊代码字符:

I am creating a RSS feed file for my application in which I want to remove HTML tags, which is done by strip_tags. But strip_tags is not removing HTML special code chars:

  & © 

请告诉我可以用来从字符串中删除这些特殊代码字符的任何函数.

Please tell me any function which I can use to remove these special code chars from my string.

推荐答案

或者使用html_entity_decode对其进行解码,或者使用preg_replace将其删除:

Either decode them using html_entity_decode or remove them using preg_replace:

$Content = preg_replace("/&#?[a-z0-9]+;/i","",$Content); 

(摘自此处)

根据雅科的评论选择

最好用'+'代替 {2,8}之类的.这将限制 更换整个的机会 未编码的'&'句子是 礼物.

might be nice to replace the '+' with {2,8} or something. This will limit the chance of replacing entire sentences when an unencoded '&' is present.

$Content = preg_replace("/&#?[a-z0-9]{2,8};/i","",$Content); 

这篇关于如何删除html特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆