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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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