I would generally say "don't use regex to work with HTML", but, on this one, I would probably go with a regex, considering that <br>
tags generally look like either :
<br>
- or
<br/>
, with any number of spaces before the /
I suppose something like this would do the trick :
$html = 'this <br>is<br/>some<br />text <br />!';
$nl = preg_replace('#<brs*/?>#i', "
", $html);
echo $nl;
Couple of notes :
- starts with
<br
- followed by any number of white characters :
s*
- optionnaly, a
/
: /?
- and, finally, a
>
- and this using a case-insensitive match (
#i
), as <BR>
would be valid in HTML
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…