|You are here: Home > Scripts > PHP BBCode Parser|
The 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.
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
[quote]John said yadda yadda yadda[/quote]
PHP.net str-replace function
Zend.com str-replace function