I’ve been looking for a good BBCode parser, and never really found any good ones that were small, easy to deploy, and worked properly. They were either really large, required the whole class deal, or just didn’t work right. All the str_replace method ones don’t account for non closed tags, so an open [b] will amke the rest of the page bold. Some of the preg_replace method ones used something like [b](.*)[/b], which something like
[b]bold[/b] not bold [b]bold again[/b]
will evaluate to
bold[/b] not bold [b]bold again
Other parsers used (.+?) which will work for multiple tags, but not nested tags, like
would evaluate to
This is fixed by adding a while loop checking preg_match of the regex.
Demo of BB Code Parser