PHP Classes

PHP Convert BBCode to HTML: Parse BBCode and render it on a HTML Web page

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 48 All time: 10,749 This week: 54Up
Version License PHP version Categories
bbcode-to-html-conve 1.0Custom (specified...5HTML, PHP 5, Text processing, Parsers
Description 

Author

This class can parse BBCode and render it on an HTML Web page.

It can take as an argument a string with text formatted using BBCode tags.

The class can parse the BBCode tags and convert them into equivalent HTML tags to return as a result.

Picture of Win Aung Cho
  Performance   Level  
Name: Win Aung Cho is available for providing paid consulting. Contact Win Aung Cho .
Classes: 11 packages by
Country: Myanmar Myanmar
Age: 61
All time rank: 24954 in Myanmar Myanmar
Week rank: 128 Up1 in Myanmar Myanmar Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
include("BBCode2HTML.php");

/**
 * example for the use of BBCode2HTML Class
 *
 * This class is free for the educational use as long as maintain this header together with this class.
 * Author: Win Aung Cho
 * Contact winaungcho@gmail.com
 * version 1.0 10-12-2022
 * Date: 10-12-2022
 */
 
$post = <<<EOD
[img h=200 w=300]http://www.structsoftlab.com/android/AndroCAD/images/logo.jpg[/img][hr/]
[a href="http://blog.civil-uni.com"]phpBLOG[s][b]Site[/b][/s][/a][hr/]
[img w=350 src="https://structsoftlab.com/images/Logo.gif" /]
[hr/]
[a ref='http://edu.structsoftlab.com'][h1]Author's HOME[/h1][/a]
[table w=600 border="1" bg="#dff" c=green]
[tr][th]name[/th][th]value[/th][th]remark[/th][/tr]
[tr][th cspan=3]Sample Table[/th][/tr]
[tr][td]Item one[/td][td a=right]345.67[/td][td]in $[/td][/tr]
[tr][td]Item two[br/]next line[/td][td a=center][b]two[/b][/td][td bg=red a=right]format[/td][/tr]
[/table]

[ol/]
[ol]
[li c="blue"]Main[/li]
[li]Heading 1[/li]
[ol]
[li]item 1[/li]
[li]item 2
[ul][li][a ref='http://edu.structsoftlab.com/forum']link 1[/a][/li]
[li][a ref='http://www.structsoftlab.com']link 2[/a] [/li]
[/ul][/li]
[/ol]
[li]item 3[/li]
[/ol]
EOD;

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

?>


Details

BBCode-to-HTML-Converter

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

BBCode-to-HTML-Converter

Demo Version

Visit following link and check demo in forum. Demo

Usage

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
[ol/]
[ol]
[li c="blue"]Main[/li]
[li]Heading 1[/li]
[ol]
[li]item 1[/li]
[li]item 2
[ul][li][a ref='http://edu.structsoftlab.com/forum']link 1[/a][/li]
[li][a ref='http://www.structsoftlab.com']link 2[/a] [/li]
[/ul][/li]
[/ol]
[li]item 3[/li]
[/ol]
EOD;

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

Features

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 winaungcho@gmail.com.

  Files folder image Files (5)  
File Role Description
Accessible without login Image file bbcode2html.jpg Data Auxiliary data
Plain text file BBCode2HTML.php Class Class source
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:48
This week:0
All time:10,749
This week:54Up