Re: PHP Built in BBCode library?
Did you try following misson's link to the PEAR HTML_BBCodeParser library? Go to the download page there and download the manual install tarball if you want to examine the code.
And keep in mind that there are alternatives to BBCode as well -- Markdown (or Markdown Extra if you need to include things like code blocks), in particular, is a little more user-friendly, since the source text is still intuitively readable (lists look like lists, stressed elements, like <strong> and <em>, are surrounded by asterisks or underscores, etc).
“Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
"It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)