| You are here: Home > Scripts > PHP BBCode Parser |
Back to ScriptsBBCode ParserThe main goal behind bb2html.php was speed and simplicity thus the syntax was made more rigid to accomodate those goals (see below). To achieve this speed we exclusively used the function str_replace over preg_replace (regular expression). Benchmarking those two functions shows around a 3 to 4 fold speed increase.
Usage Just include the string <?php include 'bb2html.php';?> And to call it simply write <?php $htmltext = bb2html($bbtext);?> Is this a one pass parser? Not yet, however syntax wise, it allows for the possiblity. The current implementation of str_replace in PHP does a pass for EACH array element. In future versions of PHP str_replace may be optimized to using an internal binary tree lookup (or something similar) which would then require a single pass, and that in turn would make this a one-pass parser. In the meantime I am entertaining thoughts of creating a real one-pass lexer in PHP. (Will post once it is done) BBCode quick reference [img]http://elouai.com/images/star.gif[/img] [url="http://elouai.com"]eLouai.com[/url] [mail="webmaster@elouai.com"]email webmaster[/mail] [size="25"]HUGE[/size] [color="red"]RED[/color] [b]bold[/b] [i]italic[/i] [u]underline[/u] [list][*]item[*]item[*]item[/list] [code]value="123";[/code] [quote]John said yadda yadda yadda[/quote] References: PHP.net str-replace function Zend.com str-replace function |