PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Piotr   simple BBCode   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Exmaple of using the class
Class: simple BBCode
Convert BBCode formatted text to HTML
Author: By
Last change:
Date: 15 years ago
Size: 1,074 bytes
 

Contents

Class file image Download
<?php
include('./classBBCode.php');
$bbcode = new bbcode(1); //1 to enable, 0 to disable bbcode

//first example - usage of pre-defined tags
 
$text = $bbcode->parse('Sample text[br]New line in my sample text[br][br]Maybe I would like to see something in [b]bold[/b]?');
  echo
$text;
/*
  this will print:

  -------------
  Sample text
  New line in my sample text

  Maybe I would like to see something in blod?
  -------------
 
  html code:
  -------------
  Sample text<br />New line in my sample text<br /><br />Maybe I would like to see something in <strong>blod</strong>?
  -------------
*/


//second example - create own tag and use it!
 
$bbcode->addTag('d', 'list', 'ul'); //create the ul tag (list)
 
$bbcode->addTag('s', 'li', 'li'); //create the li tag (position on list)

 
$text = $bbcode->parse('[list][li]Position 1[li]Second position[/list]');
  echo
$text;
 
/*
  this will print:

  -------------
  *Position 1
  *Second position
  -------------
 
  html code:
  -------------
  <ul><li />Position 1<li />Second position</ul>
  -------------
*/
?>