dongyue6199 2013-09-10 11:00
浏览 167
已采纳

放弃多个/重复的br标签

I want to remove multiple <br> tags which are repeated more than 2times, for example:

This is text blah blah...
<br><br><br><br><br><br>Another text here

Should be:

This is text blah blah...
<br><br>Another text here

I have this:

$str = preg_replace('#(<br\s?/?>)+#', '<br><br>', $str );

But this also replace simple <br> tags with 2 brs, how I could change the regular expression for this?

Thanks

  • 写回答

2条回答 默认 最新

  • dongwuqi4243 2013-09-10 11:05
    关注

    Try this one..

    #(<br\s?/?>){2,}#
    

    Codepad.

    If your <br>s include spaces in between then this follow this one -

    #(<br\s?/?>\s*){2,}#
    

    Codepad

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

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable