|
|
More with bbcode By Jonathan Street First of all we’ll set up a form so that we can submit BBcode formatted text for conversion to html. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <textarea name="bbcode"> <?php echo @$_POST['bbcode']; ?> </textarea> </form> In the same file, and I suggest at the top, you want to add the following code to handle the bbcode. This code block checks whether text has been submitted and if it has it creates an instance of the HTML_BBCodeParser class. It then uses three functions to get the text to be parsed, parse the text and then to return it. These three functions can be wrapped up into one function and I’ll use the faster method from now on. Before proceeding however a quick note on what this script is capable of doing. At present it is fairly limited. HTML_BBCodeParser is based around filters making it possible to create custom bbcode tags and significantly extend its capabilities. The reason why the above script can so far only handle bold, italic, underline, strikethrough, subscript and superscript is that only the first filter, Basic, is being used. To use other filters a configuration file is needed. [HTML_BBCodeParser] ; possible values: single|double ; use single or double quotes for attributes quotestyle = double ; possible values: all|nothing|strings ; quote all attribute values, none, or only the strings quotewhat = all ; the opening tag character open = "[" ; the closing tag character close = "]" ; possible values: true|false ; use xml style closing tags for single html tags (<img> or <img />) xmlclose = true ; possible values: a comma seperated list of filters ; comma seperated list of filters to use filters = Basic,Extended,Links,Images,Lists,Email This is the complete configuration file I’m using but we only really need to discuss the last line dealing with the filters. Listed are the five filters that are supplied with HTML_BBCodeParser. To make use of this increased functionality we need to alter the code used previously. if (!empty($_POST['bbcode'])) { //bbcode has been submitted through the text area //Process it require_once 'HTML/BBCodeParser.php'; $parser = new HTML_BBCodeParser(parse_ini_file('BBCodeParser.ini')); echo $parser->qParse($_POST['bbcode']); } When instantiating the new HTML_BBCodeParser class we supply options by parsing the configuration ini file. This then allows us to use the full set of filters supplied.
Next Page
|
![]() |
This site best viewed in a W3C standard browser at 800*600 or higher Site design by Red Squirrel | Contact © Copyright 2012 Ryan Auclair/IceTeks, All rights reserved |