Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

BBCode-Example

Sections:

Supported BB-Codes

General text:
[b] [/b] Text bold
[big] [/big] Text big
[center] [/center] Center text
[color=RGB-CODE] [/color] Colored text
[i] [/i] Text cursive
[u] [/u] Text underlined
[sm] [/sm] Text small


Tables:
[table] [/table] Table without border
[bordertable] [/bordertable] Table with border
[cell] [/cell] Table cell
[row] [/row] Table row


Listings:
[*] Marker point
[block] [/block] Listing with tabstops


Images:
[img] [/img] Show a image


Lines:
[hr] Draw a horizontal line


Example Code

The following code demonstrates how to use the lib with a small example and some hints.

<?php
/*!***********************************************************************
 *************************************************************************
 * \file            bb-code-sample.php
 *
 * \author          Kai Klenovsek
 *
 * \date            First Step: 2004-12-22
 *
 * \note <br>
 * \b THE \bBEER-WARE \bLICENSE <br>
 *   As long as you retain this notice you can do whatever you want with <br>
 *   this stuff. If we meet some day, and you think this stuff is worth it, <br>
 *   you can buy me a beer in return. <br>
 *
 * \b NOTES: <br>
 *   
***************************************************************************
***************************************************************************/

// NOTE THAT THIS SAMPLE IS OPTIMIZED FOR XAMPP !!

// First we have to include the phplibex 
require("../../phplibex.inc.php");
    
/* $smilie_file  = Absolut path to the smilie database file
 * $smilie_url   = URL to the smilie folder with smilies
 * If you dont want any smilies let the vars empty !! */
$smilie_file = "C:/apachefriends/xampp/htdocs/phplibex/samples/bb-code/bbcode_smilies/smilielist.db";
$smilie_url  = "http://localhost/phplibex/samples/bb-code/bbcode_smilies";

// Load BB-Code examples into string variable
$string  = "[big]General text:[/big]\r";
$string .= "[b]This text is bold.[/b]\r";
$string .= "[big]This text is big.[/big]\r\r";
$string .= "[center]This text is centered.[/center]\r";
$string .= "[i]This text is cursive.[/i]\r";
$string .= "[u]This text ist underlined.[/u]\r";

$string .= "\r[big]URLs:[/big]\r ";
$string .= "www.sourceforge.net\r ";
$string .= "http://phplibex.sourceforge.net\r ";
$string .= "kai.klenovsek@gmx.net\r ";
$string .= "ftp://nowhere.org\r ";
  
$string .= "\r[big]Tables:[/big]\r";
$string .= "[table][row][cell]I`m a table without a border.[/cell][/row][/table]\r";
$string .= "[bordertable][row][cell]I`m a table with border.[/cell][/row][/bordertable]\r";
$string .= "[b][color=#ff0000]This text is colored in red and bold[/color][/b]\r";
  
$string .= "\r[big]Listings:[/big]\r";
$string .= "[*] <-- This marker point\r";
$string .= "[block] 1.1 List1 \r1.2 List2[/block]";

$string .= "\r[big]Smilies:[/big]\r";
$string .= ":( :) :D ;) :angry: :bounce: :confused: :cool: :evil: :headbang: :rolling:\r";
  
$string .= "\r[big]Horizontal line:[/big]\r";
$string .= "[hr]\r";

// Lets create an object from class bbcode.
$bbcode = new bbcode($string, $smilie_file, $smilie_url);

/* Let us format the string with BB-Code into HTML code
 * Note that it is also possible to convert the string step by step.
 * For this take a look into the doc or class source. */  
echo $bbcode->bbcode_bb2html( );

$error = $bbcode->bbcode_get_errorlist(); 

// Echo error messages
if ( sizeof($error) >= 1 )
{
    echo "<b>Error Messages:</b><br>";
    for ( $loop=0; $loop <= sizeof($error); $loop++ )
        echo $error[$loop]."<br>";    
}

?>

How to build a smilie database file

:(|cry.gif
:)|lol.gif
:D|lollol.gif
;)|zwinker.gif
:angry:|angry.gif
:bounce:|bounce.gif
:confused:|confused.gif
:cool:|cool.gif
:evil:|evil.gif
:headbang:|headbang.gif
:rolling:|rolling.gif

The "|" sign is the seperate sign between the BB-Code (eg. ":cool:") and the name of the gif (eg. "cool1.gif"). The database file must be saved in the same folder like the smilie pictures.

Related links

What is BB-Code: http://en.wikipedia.org/wiki/Bbcode
Generated on Fri Aug 26 08:13:54 2005 for PHP-Lib-Xtreme by  doxygen 1.4.3