Hi everyone I had previously posted about a
getting inserted at the beginning of my text and we got that fixed. (here is my previous post with the code)
This should do it, matches <br>
, <br/>
or <br />
at the start or end:
preg_replace('#^<br(\s*/)?>|<br(\s*/)?>$#i', "\n", $str);
The tag is matched by:
* Literal <br
* Optional spaces followed by a forward slash
The |
in the middle is used to denote an alternative condition (i.e. OR
).
Edit
Instead of <br(\s*/)?>
you can also write <br(\/|)>
that you had before.
Edit 2
Multiple occurrences can be matched by just adding +
behind each pattern:
preg_replace('#^<br(\/|)>+|<br(\/|)>+$#i', "\n", $str);