BBEngine is a PHP Dynamically Extendable BBCode Parsing/UnParsing Engine 

Downloads 

The Class from phpclasseshere : http://www.phpclasses.org/browse/package/4829.html

Class Documentation here :  http://harrrrpo.googlepages.com/BBEngine_Docs.zip

Features

1)It depends on saving tags info in a DB for easy Extendability (as it provides out-of-code dynamic of adding , removing and  deleting )

2)Provides Means for Parsing BBCode => Html and Html => BBCode (Can be customized for any other tag-based languages)

3)Provides Processing Priority  for each tag allowing for writting tags that depends on each others with no code modifications and also for clash avoidance

3)The Class Provides Parsing/UnParsing in 4 types

  • Direct :-
a)Direct Words : Directly replace words with others like ( :) =>Smile photo (html <img>) )
b)Direct Tags    : Replace Html Tags with BBCode directly (text replace) like ( [b]ASD[/b] => <strong>ASD</strong> )
  • Indirect :-
c)Indirect Non Recursive : Mainpulate content in BBCode with user defined function both for Parsing &  UnParsing (Stored in DB) Content and Arguments of BB tag is supplied to the function here BBCode tags can't be Nested like ( [url=http://google.com]Google[/url] => <a href="http://google.com">Google</a> )
d)Indirect Recursive          : The Same Indirect manner with the added ability of Parsing Nested tags like ( [size=20]Big [size=40]Bigger[/size]Word[/size] => <span style="font-size: 20px;">Big<span style="font-size:40px;">Big Label</span>Word</span> )

4)It also comes with some pre-made BBCodes as an SQL dump to provide most famous BBCodes

Detailed Example :-

let's take the list case study a very good example , a typical list BBCode :-

[list][*]One[list=1][*]One/One[list=A][*]One/One[*]One/Two[/list][*]One/Two[/list][/list][list][*]Two[list=1][*]Two/One[*]Two/Two[/list][/list]

which should produce something like :-

  • One
    1. One/One
      1. One/One
      2. One/Two
    2. One/Two
  • Two
    1. Two/One
    2. Two/Two

 Nested and complex enough 

first note that [*] doesn't have [/*] which is a problem

we apply it in two steps :-

1) First , add a Direct word replace as [*] => </li><li> which is a nice trick by which evey element can be multiline and don't need [/*] it''s only side effect is the added </li> which browsers - i know - simply ignore

2) Second , add a Recursive Indirect replace for the [list] tag in following two functions (function declarators are always cut as functions are created dynamically in scripts using createfunction()

if (isset($Args['list']))
{ $tag="ol";
$type=" type=\"".$Args['list'].'"'; }
else
{$tag="ul";$type="";}
return "<{$tag}{$type}>$Data</$tag>";

and Reversing function here :

$type="";
preg_match("#<ul>(.*?)</ul>#",$Data,$m);
if ($m==null)
{ preg_match("#<ol type=\"([0-9a-zA-Z])\">(.*?)</ol>#",$Data,$m);
$type="=".$m[1]; $m[1]=$m[2]; }
return "[list{$type}]$m[1][/list]";

And that's all , The class takes care after that if nesting problems and is connected always of your DB Stored functions providing you anytime further with Parsing & UnParsing capabilities .