Need a solid bbcode parser in PHP

The problem I have come across is - there are so many out there and many people commenting it’s hard to find a good one so I’m a bit lost. I need a bbcode parser for a community site with the following requirements:

  • support for all common bbcode tags including nested quoting, embedding images, youtube videos
  • automatic link recognition and shortening long links for display
  • smileys
  • quite secure against malicious html/js injection
  • error free when fed malformed content
  • a nice addition would be well structured OO interface and configurable (like custom tags, disallowing chosen tags, etc.)

I could write my own function with a few regex expressions but I’d rather use something mature and tested. If anyone has had good experience with a library like that I’d be happy to hear.

I did see this on GitHub; it uses a ‘proper’ parser too.

I’d like to cast my vote for that parser too.
I spent ages looking for a decent BBCode parser, that’s definitely the best one I found.

Thanks, I will definitely check it out.

I have just found NBBC which looks like an advanced and well-maintained project. Have you tried it?

I haven’t tried that one, but it certainly looks interesting.
If you do investigate it, could you share your thoughts on it?


I decided to try out NBBC first and have now only a few first impressions:

  1. Very easy to install and use.

  2. I wanted to chage the default English text for [ quote ] like “XXX wrote” and “Quote:” - it was hard-coded. Fortunately, I was able to easily overwrite the whole method for the [ quote ] tag. However, some better customization would be welcome.

  3. I wanted to set default target=“_blank” for links - no problem.

  4. I wanted to enable link auto-detection, it was very easy but the class is buggy here because it detects too much so when I use the [ url ] tag for link then I get two nested <a> tags. I had to use a regex afterwards to get rid of that.

  5. I cannot find a way to shorten long links automatically, certainly it can be done but it’s not very straightforward and may require a bit of hacking (=overwriting methods).

  6. The conversion seems to be pretty fast.

Generally, the code looks well written (but still for php 4) and separated in different classes. However, I think it would need more attention from the developer to fix some bugs and get a few small features more polished.

When I have time I will try StringParser but for now I have to carry on with my project and focus on other things. Do you have any experience with StringParser regarding the points above?