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);
give a positive ratinggive a negative rating
27 Jul 2019 at 05:50 PM

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 />
give a positive ratinggive a negative rating
01 Aug 2019 at 07:54 PM
Share on FacebookShare on TwitterShare on LinkedInSend email
2023 AnswerTabsTermsContact us
How would you rate your experience with AnswerTabs ?
Very badVery good
Thank you for your feedback.