PHP Classes


Recommend this page to a friend!
  Classes of Win Aung Cho   PHP Convert BBCode to HTML   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Convert BBCode to HTML
Parse BBCode and render it on a HTML Web page
Author: By
Last change:
Date: 9 months ago
Size: 1,277 bytes


Class file image Download


A class to render BBCode string and convert to HTML string.


Demo Version

Visit following link and check demo in forum. Demo


First include the BBCode2HTML.php class in your file, and use the class as following to generate the HTML for the BBCode expressions:

$pist = <<<EOD
[li c="blue"]Main[/li]
[li]Heading 1[/li]
[li]item 1[/li]
[li]item 2
[ul][li][a ref='']link 1[/a][/li]
[li][a ref='']link 2[/a] [/li]
[li]item 3[/li]

$bb2html = new BBCode2HTML();
echo $bb2html->parse($post);


Algorythm is very simple.

  • String is recursively tokenized using `preg_match` into array of matches,
  • Matches types are tag, attributes and inner-html.
  • Tag ommitting can be detected.
  • Data base classes are formed for each tags.
  • Tags data are then converted to html while filtering allowed tags and allowed attributes.
  • Value names of attributes are converted through short-cut name list.
  • `allowattr` flag control to allow native attributes of html. ## Contact Contact me for comercial use via mail