how can I remove excess <br> and
tags from the start and end of a string?
如何删除多余的
和 字符串的开头和结尾的标签?
Thanks :)
2 个解决方案
#1
try this:
$str = preg_replace('{^(<br(\s*/)?>| )+}i', '', $str); //from start
$str = preg_replace('{(<br(\s*/)?>| )+$}i', '', $str); //from end
that also gets XHTML <br />
and <br/>
forms
这也得到XHTML
和形式
#2
With preg_replace:
$str = "<br>some text "
$str = preg_replace('/(^(<br>| )*)|((<br>| )*$)/i', '', $str);
Didn't test it, but something like that should work.
没有测试它,但这样的东西应该工作。
#1
try this:
$str = preg_replace('{^(<br(\s*/)?>| )+}i', '', $str); //from start
$str = preg_replace('{(<br(\s*/)?>| )+$}i', '', $str); //from end
that also gets XHTML <br />
and <br/>
forms
这也得到XHTML
和形式
#2
With preg_replace:
$str = "<br>some text "
$str = preg_replace('/(^(<br>| )*)|((<br>| )*$)/i', '', $str);
Didn't test it, but something like that should work.
没有测试它,但这样的东西应该工作。