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 :-
- Indirect :-
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
- One/One
- One/One
- One/Two
- One/Two
- One/One
- Two
- Two/One
- 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 .