# BBCode parser for PHP

I am searching for a BBCode parser for PHP. I tried many but none of them fit exactly what I want. I will take the example of [quote] to explain what I need:

All I want to do is to parse:

• [quote]something[/quote]<blockquote>something</blockquote>

• It can take a parameter, the "source" here, which is optional.

[quote="source"]something[/quote]<blockquote><cite>source</cite>something<blockquote>

• You can set the nest limit to forbid unlimited nesting like:

[quote]111[quote]222[quote]333[quote]444[quote]555[ETC][/quote][/quote][/quote][/quote][/quote]

Set to 3, it will give me:

<blockquote>111<blockquote>222<blockquote>333[quote]444[quote]555[ETC][/quote][/quote]</blockquote></blockquote></blockquote>

• When the tags are empty, they are not changed in the wanted result but displayed as it is (because if someone posts empty tags in my website, the comment will be empty but valid until I set an additional checker for "comments filled with empty tags only"):

[quote]something[quote][/quote][/quote] must become <blockquote>something[quote][/quote]</blockquote>

I don't feel like asking too much but, until now, inventors of the wheel failed at giving me something perfectly circular.

Of course, I need the parser to be customizable (I could create my own tags like [spoiler] or [youtube]), I could also check the parameter and the content (parameter N of [size=N] must be between x and y values, [url]content[/url] → content must be a valid URL).

Is there at least one existing customizable BBCode parser that can fit that set of criteria? If that's the case, which one? I am not asking for the BEST plugin, just link me ONE, if that's even possible. (In case nothing can be found, I can live without the nest limit.)

Here are my previous attempt with popular parsers and why they failed my test. I posted this report in appendix, in case I missed something. If that's the case, point me the name of the parser and tell me why I am wrong.

• BBCode PECL extension:

• Cannot set a nest limit.
• Tags removed if content is empty.
• Moreover, I had a problem I still didn't solve (maybe because I am bad at OOP), not that matters anymore.
• PEAR HTML_BBCodeParser2:

• Convert your tag attribute in HTML tag attribute only.
[quote="source"]something[/quote] will turn as <blockquote cite="source">something</blockquote>
• A tag attribute must be true OR false, not true AND false i.e. it can't be an option.