scrub document of BBcode
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. An开发者_如何学Pythond 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.
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);
精彩评论