BBCode 需要 preg_replace 帮助
我不太清楚与 PHP 的 preg_replace 函数一起使用的正确模式。这是 phpBB 论坛上的一些 BBCode 的示例。
[color=black][font=Times New Roman][color=black]Thanks. As discussed last night/this morning, we were able to Cable and provide some small relief. After enough waste water was evacuated, the camera diagnosis found at 30 foot from clean-out, heavy root penetration and possible damage/separation to the line. We don’t want to throw a cost to fix/repair without a second opinion from xxx. We will have solid cost of repair later today of first thin in the morning. [/color][/font][/color]
我想删除可能嵌入文本中的任意数量的开始和结束字体标签,但将文本保留在中间。在这种情况下,我想最终得到:
[color=black][color=black]Thanks. As discussed last night/this morning, we were able to Cable and provide some small relief. After enough waste water was evacuated, the camera diagnosis found at 30 foot from clean-out, heavy root penetration and possible damage/separation to the line. We don’t want to throw a cost to fix/repair without a second opinion from xxx. We will have solid cost of repair later today of first thin in the morning. [/color][/color]
字体的名称各不相同,有些名称中包含空格,有些则没有。无论如何,模式匹配都必须有效。
提前致谢!
I can't quite figure out the right pattern to use with PHP's preg_replace function. Here is an example of some BBCode on a phpBB forum.
[color=black][font=Times New Roman][color=black]Thanks. As discussed last night/this morning, we were able to Cable and provide some small relief. After enough waste water was evacuated, the camera diagnosis found at 30 foot from clean-out, heavy root penetration and possible damage/separation to the line. We don’t want to throw a cost to fix/repair without a second opinion from xxx. We will have solid cost of repair later today of first thin in the morning. [/color][/font][/color]
I'd like to remove the opening and closing font tags, any number of them, that might be embedded in the text, but keep the text in between. In this case, I would like to end up with:
[color=black][color=black]Thanks. As discussed last night/this morning, we were able to Cable and provide some small relief. After enough waste water was evacuated, the camera diagnosis found at 30 foot from clean-out, heavy root penetration and possible damage/separation to the line. We don’t want to throw a cost to fix/repair without a second opinion from xxx. We will have solid cost of repair later today of first thin in the morning. [/color][/color]
The name of the fonts vary, some have spaces in the names, some don't. The pattern match would have to work regardless.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只是删除它们,则不需要太复杂的正则表达式...
输出
在 ideone 上查看。
If you are simply removing them, you don't need a too complicated regex...
Outputs
See it on ideone.