Reputation: 404
My comment has so much
<br>
<br>
<br>
<br>
<br>
tags
how to replace these br tags to one?
this one doesn't work for me
$text = preg_replace('#<br\s*/?>#i', "\n", $text);
Upvotes: 0
Views: 596
Reputation: 89557
You can try this:
$text = preg_replace('~(?:<br\b[^>]*>|\R){2,}~i', "\n", $text);
where \R
matches any type of newlines and [^>]
, all characters except >
.
Upvotes: 4