duanrenchuo9244 2009-11-22 07:18
浏览 359
已采纳

如何从字符串中删除<br />标签和更多?

I need to strip all <br /> and all 'quotes' (") and all 'ands' (&) and replace them with a space only ...

How can I do this? (in PHP)

I have tried this for the <br />:

   $description = preg_replace('<br />', '', $description);

But it returned <> in place of every <br />...

Thanks

  • 写回答

6条回答 默认 最新

  • doufei4418 2009-11-22 07:23
    关注

    To manipulate HTML it is generally a good idea to use a DOM aware tool instead of plain text manipulation tools (think for example what will happen if you enounter variants like <br/>, <br /> with more than one space, or even <br> or <BR/>, which altough illegal are sometimes used). See for example here: http://sourceforge.net/projects/simplehtmldom/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部