scrub document of BBcode

早过忘川 提交于 2020-01-06 21:15:28

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/6260194/scrub-document-of-bbcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!