the PEAR project has support for BBCode via the HTML_BBCodeParser. I've used it in some projects of mine and it works quite well.

This is a good tutorial on how to use it.