How to remove / replace multiple <br /> line breaks in PHP ?
I need to replace multiple <br /> line break tags with one single <br /> tag. I have tried to do so by Regex pattern below, but it doesn't work. Can you please give me suggestion how should the Regex pattern look like, to make it work correctly ?
preg_replace("/(<br\s*\/>)+/", "<br />", $content);
Hi,
To replace multiple <br /> line breaks with single line break, you have to use the following Regex pattern:
$updatedcontent = preg_replace("/(<br\s*\/>\s*)+/", "<br />", $content);
When you are using nl2br() function to convert the content from textarea, there is often some whitespace after each line break tag, so the code looks like:
<br /> <br /> <br />
1 answer