BBCode generator PHP HTML decoder script

About BBCode generator PHP HTML decoder script

This BBCode generator PHP HTML decoder script has the following features.

  1. It has a nice looking wysiwyg editor which allows visitors to generate BBCode text.
  2. You can easily plug-in this editor to your existing WebPages.
  3. You can add this wysiwyg editor to any type (*.html, *.php, etc.) webpage.
  4. You can set your desired size (height and width) of the editor to plug-in.
  5. This script supports BBCode for link, list, image and color.
  6. The PHP code behind this editor can successfully decode this BBCode into its HTML equivalent.
  7. A preview script is also included with this script package which you can optionally use with your system.

Server requirements:

Any web server which has PHP installed can handle this script. Even if your system doesn't have PHP installed you can use the JavaScript BBCode generator to generate BBCode.

Installation:

This script is of plug and play type and hence doesn't require any installation. To use this script,

  1. Download the compressed file by using the link below.
    php-bbcode-html-generator-editor-v1.0.zip
  2. Unpack the compressed file to your local computer.
  3. Use FTP program to upload the "BBCode" folder to any directory or subdirectory under "www" or "public_html" folder of your web server.
  4. After or before uploading you are free to delete the following files. They are provided only for demonstration purpose.
    • BBCode/demo.htm;
    • BBCode/script/comment.js;
    • BBCode/images/bg.gif;
    • BBCode/images/caption.gif;

Now the editor is ready for use.

How to add wysiwyg BBCode editor to WebPages

As I said you can add this wysiwyg BBCode editor to WebPages of any extension. Here is the guideline to add this script.

  1. Between <head> and </head> tags of your webpage insert the link of the JavaScript file bbcode.js.
    <script type="text/javascript" src="BBCode/script/bbcode.js"></script>
  2. Put a blank division or table cell inside the body tag where you like to put this editor to display.
  3. At the end of the webpage just before the closing body tag (</body>) inserts the following lines code.
Code | Download
<script type="text/javascript">
<!--
addBBcode("division",680,150);
-->
</script>

In the above code

  • Here "division" is the element id where you want to add the editor;
  • 680 and 150 are the desired width and height in pixel of the editor.

Sending BBCode text to the server

You can use AJAX or conventional form submit method to send BBCode text to your server. To generate preview I use AJAX post submit method to recover HTML from BBCode text. The id and name value of the editor textarea is "fw_editor". You can change the editor name value and id by editing the first two lines of the JavaScript file "script/bbcode.js".

PHP BBCode to HTML

The BBCode text as received by the server can be decoded to HTML by a series of PHP functions included in the file include/functions.php. To decode BBCode you have to include this file and call the function fw_format_text(). This function takes to mandatory arguments BBCode text and auto link. The argument auto link is of Boolean type and when set converts all the URL text into clickable links. Below, I give the PHP code example to demonstrate how to handle this BBCode text at the server end.

Code | Download
Receive data from user:
<?php
$comment=stripslashes(trim($_POST['fw_editor']));
//Other post vriables.
//Verify data whether they obey proper guideline as set by you.
//Store data into database.
?>

Reconstruct HTML code.
<?php
include "BBCode/include/functions.php";
//Call data from database as $comment.
$comment=fw_format_text($comment,true);
//Second argument is set to automatically convert URLs to clickable links.
//Display comment.
?>

Copyright:

This product is protected by copyright and distributed under licenses restricting copying, distribution. Permission is granted to the public to download and use this script provided that this Notice and any statement of authorship are reproduced in every page on all copies of the script.

DISCLAIMER OF WARRANTIES:

THIS SCRIPT PRODUCT IS PROVIDED "AS-IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. YOU (RECIPIENT) USE THIS SCRIPT AT YOUR (RECIPIENTS) OWN RISK. TO THE MAXIMUM EXTENT PERMITTED UNDER APPLICABLE LAWS, AUTHOR EXPRESSLY DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. AUTHOR DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE SCRIPT WILL MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF THE SCRIPT WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT DEFECTS IN THE SCRIPT WILL BE CORRECTED. FURTHERMORE, AUTHOR DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF THE USE OF THE SCRIPT IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY, OR OTHERWISE. NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY AUTHOR OR RAMUI.COM SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE SCOPE OF ANY WARRANTY.

Download:
php-bbcode-html-generator-editor-v2.0.tar.gz
Comments:

Add comment