scrub document of BBcode

2019-08-17 23:09发布

Say I have a document like:

 [b]blah[/b]
 [img]Thisismyimage.png[/img]

How can I make it so that I completely remove all of the BBcode tags. And also remove all the text from between the [img] tags.

If it helps at all I am using an IPB board. If any knows of a way to easily to parse the BBcode that would be great, however, I am perfectly happy with just removing it.

标签: php bbcode ipb
1条回答
干净又极端
2楼-- · 2019-08-17 23:44

Parsing BBcode is pretty much a solved task: http://pear.php.net/package/HTML_BBCodeParser - And that would also be the more advisable path for removing (for simplicity just apply strip_tags() afterwards).

But for removing a limited set of syntax constructs, you could use a very simple regex:

 $text = preg_replace('#\[img].*?\[/img]|\[/?\w+.*?]#', '', $text);
查看更多
登录 后发表回答