[dev] Possible replacement for Text_Filter_BBCode

Stephan Hohmann webmaster at dasourcerer.net
Fri Mar 14 18:42:13 UTC 2008


Hello,

I've been working on a BBCode parser for a while now and I am so convinced of
its qualities that I think it might be a suitable replacement for the current
Text_Filter_BBCode class.

The initial motivation was to find a new parser for a forum that I maintain.
For our next release we planned to have XHTML output. This soon prooved to
be a problem, since most available parsers won't check for the validity of
their output and will only perform search/replace operations via str_replace
(or preg_replace if they are a bit more sophiscticated). This is critical as
not all combinations of BBCodes will lead to valid (X)HTML. I found this to be a good test for parsers:
   [i]foo [b]bar[/i] baz[/b]

Since it is not uncommon for our userbase to post while being intoxicated, I
could not possibly rely on them to post BBCodes that would ultimately result
in valid XHTML, thus I had to write a parser that builds a parse tree and would
autocorrect nesting etc. as needed.

Shortly after I began work on this, several people started asking me about the
finished parser, so I wrote it to be more generic.
Now it is far from being finished (there's still a lot of optimizations to do.
Not to mention code cleanups, more documentation and some refactoring) but I
feel it is far enough to be discussed.
I hereby invite you to have a look at my latest hackjob:
   <http://snafu.dasourcerer.net/bbcode/>
   <http://snafu.dasourcerer.net/bbcode/BBCode.phps>

With best regards,
   Stephan



More information about the dev mailing list