剥离 phpbb bbcode
我想在我的网站上显示 phpbb3 论坛的最新帖子,但没有 bbcode。 所以我试图去掉 bbcode 但没有成功 例如,其中一篇文章可能是:
[quote="SimonLeBon":3pwalcod]bladie bla bla[/quote:3pwalcod]bla bla bladie bla blaffsd
fsdjhgfd dgfgdffgdfg
要删除 bbcodes,我使用通过谷歌找到的函数,我也尝试了其他几个类似的函数:
<?php
function stripBBCode($text_to_search) {
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);
}
?>
但这实际上没有任何效果。
I want to display the most recent posts from my phpbb3 forum on my website, but without the bbcode.
so I'm trying to strip the bbcode but without succes
one of the posts for example could be:
[quote="SimonLeBon":3pwalcod]bladie bla bla[/quote:3pwalcod]bla bla bladie bla blaffsd
fsdjhgfd dgfgdffgdfg
to strip bbcodes i use the function i found via google, I've tried several other similiar functions aswell:
<?php
function stripBBCode($text_to_search) {
$pattern = '|[[\/\!]*?[^\[\]]*?]|si';
$replace = '';
return preg_replace($pattern, $replace, $text_to_search);
}
?>
This however doesn't really have any effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这将剥离有效的 bbcode(即开始标记与结束标记匹配)。
键盘。
可重用函数
说明
\[
匹配文字[
。(\w+)
匹配 1 个或多个单词字符并保存在捕获组1
中。=
匹配文字=
。.*?
贪婪地匹配=
和:
之间除\n
之外的所有字符。:
匹配文字:
。(.*?)
贪婪地匹配:
和]
之间除\n
之外的每个字符,并保存在捕获组 <代码>2。\]
匹配文字]
。(.*?)
贪婪地匹配:
和]
之间除\n
之外的每个字符,并保存在捕获组 <代码>3。\[
匹配文字[
。/\1\2
再次匹配之前的捕获组。\]
匹配文字]
。This will strip bbcode, that is valid (i.e. opening tags matching closing tags).
CodePad.
Reusable Function
Explanation
\[
match literal[
.(\w+)
Match 1 or more word characters and save in capturing group1
.=
Match literal=
..*?
Match ungreedily every character except\n
between=
and:
.:
Match literal:
.(.*?)
Match ungreedily every character except\n
between:
and]
and save in capturing group2
.\]
Match literal]
.(.*?)
Match ungreedily every character except\n
between:
and]
and save in capturing group3
.\[
Match literal[
./\1\2
Match previous capturing groups again.\]
Match literal]
.这是来自 phpBB 的一个(稍微调整为独立的):
Here's the one from phpBB (slightly adjusted to be standalone):
为什么不使用 PHP 内置的 BBCode 解析工具?
http://php.net/manual/en/book.bbcode.php
Why don't you use the BBCode parsing facilities that are built in to PHP?
http://php.net/manual/en/book.bbcode.php
现在使用phpbb自带的函数https://wiki.phpbb.com/Strip_bbcode
Nowadays, use phpbb's own function https://wiki.phpbb.com/Strip_bbcode