连续显示的 br's nl2br 数量是否有限?
我正在编码的“bb 解析器”遇到一些问题。或者,不是解析器本身,而是 nl2br 修改它。
数据库中的字符串如下所示:
text text text
[code]code code code[/code]
text text text
现在,nl2br 在第一个“text text text”后面放置一个 br /,然后在其下面放置另一个,因此[code] 标签之前有两个换行符(实际上是正确的,但不是我想要的)。
有什么方法可以限制连续输入多少个 br?我似乎找不到足够简单的解决方案。
预先感谢各位。
I'm having some problems with a "bb parser" I'm coding. Or, well, not with the parser itself, but the nl2br modifying it.
The string from the database is like the following:
text text text
[code]code code code[/code]
text text text
Now, nl2br puts one br / after the first "text text text", and then another one below that, so there's two line breaks before the [code] tag (which actually is correct, but not what I want).
Is there any way I can limit how many br's are entered in a row? I can't seem to find a solution that's simple enough.
Thanks in advance, guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了之前的解决方案之外,我还添加了一个不同的解决方案,因为 Fredrik 要求这样做。这将替换 nl2br 之后而不是之前的双
。In addition to previous solution, I add a different one, since Fredrik asked for it. This will replace double
<br>
after nl2br instead of before.例如,您可以使用 preg_replace 将两个(或多个)换行符替换为一个换行符:-)
You could for example replace two linebreaks (or more) by one by using preg_replace :-)
您可以使用
这可以防止双重
;标签。如果一行中可能有两个以上的新行,则按照之前的建议进行 Preg_replace 会更好。
You could use
This prevents double <br> tags. Preg_replace as suggested before is better if there could be more than two new lines in a row.