How to convert multiple
tag to a single
tag in php

后端 未结 9 1256
执念已碎
执念已碎 2020-12-03 02:03

Wanted to convert






into


相关标签:
9条回答
  • 2020-12-03 02:31

    Use a regular expression to match <br/> one or more times, then use preg_replace (or similar) to replace with <br/> such as levik's reply.

    0 讨论(0)
  • 2020-12-03 02:32

    Thanks all.. Used Jakemcgraw's (+1) version

    Just added the case insensative option..

    {(<br[^>]*>\s*)+}i
    

    Great tool to test those Regular expressions is:

    http://www.spaweditor.com/scripts/regex/index.php

    0 讨论(0)
  • 2020-12-03 02:34

    Enhanced readability, shorter, produces correct output regardless of attributes:

    preg_replace('{(<br[^>]*>\s*)+}', '<br/>', $input);
    
    0 讨论(0)
提交回复
热议问题