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
Post a Comment