Posted By

pumpkinthehead on 06/27/12


regex php wordpress regular Expression nl2br

Versions (?)

Remove superfluous line breaks between HTML elements.

 / Published in: PHP

A regular expression for removing and (case insensitive) between HTML elements if there is no content between the HTML elements. It was written for fixing extra line spaces created in a WordPress visual editor after the content of the visual editor was returned from the PHP nl2br() method.

  1. $output = preg_replace('/<(((?!br)[^>])*)>\r*\n*\s*(<br\s?\/?>)*\r*\n*\s*<(((?!br)[^>])*)>/i', '<$1><$4>', $output);

Report this snippet  

You need to login to post a comment.