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条)

报告相同问题?