如何删除html特殊字符?

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


  & © 

等等


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


慕仙森
浏览 782回答 3
3回答

繁华开满天机

使用解码html_entity_decode或使用删除它们preg_replace:$Content = preg_replace("/&#?[a-z0-9]+;/i","",$Content); (从这里)编辑:根据雅科的评论的替代用{2,8}或其他内容替换'+'可能会很好。当出现未编码的“&”时,这将限制替换整个句子的机会。$Content = preg_replace("/&#?[a-z0-9]{2,8};/i","",$Content); 

翻过高山走不出你

使用html_entity_decode转换HTML实体。您需要设置字符集以使其正常工作。

阿晨1998

您可能想在这里看看htmlentities()和html_entity_decode()$orig = "I'll \"walk\" the <b>dog</b> now";$a = htmlentities($orig);$b = html_entity_decode($a);echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; nowecho $b; // I'll "walk" the <b>dog</b> now
打开App,查看更多内容
随时随地看视频慕课网APP