Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BBCode parser without Regex? [closed]

I'm looking for a BBCode parser in Javascript or PHP without the need of using Regex. Can anybody suggest me a good one?

like image 937
Teiv Avatar asked May 25 '11 17:05

Teiv


3 Answers

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.

like image 169
MacMac Avatar answered Sep 22 '22 00:09

MacMac


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.

like image 42
onteria_ Avatar answered Sep 22 '22 00:09

onteria_


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.

like image 40
Frank Farmer Avatar answered Sep 21 '22 00:09

Frank Farmer