I'm looking for a BBCode parser in Javascript or PHP without the need of using Regex. Can anybody suggest me a good one?
It is recommended to use regex.
Other solution:
function bb_parse($str)
{
return str_replace(array('[b]', '[/b]'), array('<strong>', '</strong>'), $str);
}
This can break parsing due to mis-closing tags can end up content being wrapped with a HTML tag without closing.
There's a PECL extension for bbcode. You'll need to take a look on how to install PECL extensions in order to utilize it.
Zend parser might be what you're looking for http://framework.zend.com/manual/en/zend.markup.parsers.html
Unfortunately, I found it the least practically functional of the BBCode parsers I evaluated: when encountering malformed markup ([b] asdf [/ wops I forgot to close my tag
) it tends to throw away all content after the first malformed tag. Other bbcode parsers do a much better job of simply ignoring bad markup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With