So the function nl2br is handy. Except in my web app, I want to do the opposite, interpret line breaks as new lines, since they will be echoed into a pre-filled form.
<You can use br2nl() for nl2br() reversal.
There will probably be some situations where your code is not enough ; so, what about something like this, to do your replacement :
$html = 'this <br>is<br/>some<br />text <br />!';
$nl = preg_replace('#<br\s*/?>#i', "\n", $html);
echo $nl;
i.e. a bit more complex than a simple str_replace
;-)
Note : I would generally say don't use regex to manipulate HTML -- but, in this case, considering the regex would be pretty simple, I suppose it would be OK.
Also, note that I used "\n"
\n
\n
Basically, a <br>
tag generally looks like :
<br>
<br/>
, with any number of spaces before the /
And that second point is where str_replace
is not enough.