php - Remove every <br /> except one per line? -


how can turn this:


...<br /> <br /> ...<br /> ...<br /> <br /> <br /> ...<br /> 

into using php:

...<br /> ...<br /> ...<br /> ... 

please notice deletion of first , last
if it's mentioned once. in middle keep 1

preg_replace('#<br />(\s*<br />)+#', '<br />', $your_string); 

this replace instances of more 1 <br />, optionally whitespace separating them, single <br />.

note <br /> in pattern matches that. if wanted more defensive, change <br[^>]*> allow <br> tags have attributes (ie. <br style="clear: both;" />) or don't have trailing slash.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -