how can I remove excess <br> and
tags from the start and end of a string?
Thanks :)
how can I remove excess <br> and
tags from the start and end of a string?
Thanks :)
try this:
$str = preg_replace('{^(<br(\s*/)?>|ANDnbsp;)+}i', '', $str); //from start
$str = preg_replace('{(<br(\s*/)?>|ANDnbsp;)+$}i', '', $str); //from end
that also gets XHTML <br />
and <br/>
forms
note: replace "AND" with an ampersand above (can't figure out how to get the software to not turn it into an actual non-breaking space)
With preg_replace:
$str = "<br>some text "
$str = preg_replace('/(^(<br>| )*)|((<br>| )*$)/i', '', $str);
Didn't test it, but something like that should work.