A week last Friday I posted about an article I wrote for the iceteks website looking at handling BBCode using the HTML_BBCodeParser package available from the PEAR repository. I ended the article by talking about alternatives one of which was the Text_Wiki package. In this post I go into a little more detail about using the Text_Wiki and Text_Wiki_BBCode packages.
Just as with the HTML_BBCodeParser the Text_Wiki and Text_Wiki_BBCode packages are easy to use. First lets look at the Text_Wiki_BBCode package as handling BBCode is what I'm focusing on.
<?phpif (!
empty($_POST['text'])){ echo '<div style="border: solid 1px orange; padding:20px; margin: 20px">';
// load the class filerequire_once 'Text/Wiki/BBCode.php';
// instantiate a Text_Wiki object with the default rule set$wiki =&
new Text_Wiki_BBCode
();
// load some wiki text from a file or database$text =
$_POST['text'];
// transform the wiki text into XHTML$xhtml =
$wiki->
transform($text,
'Xhtml');
// display the transformed textecho $xhtml;
echo '</div>';
}?><form action=
"<?php echo $_SERVER['PHP_SELF']?>" method=
"post">
<textarea name=
"text" style=
"width: 300px; height: 200px"><?php
echo @
$_POST['text']; ?></textarea>
<br />
<input type=
"submit" />
</form>
The layout used is exactly the same as for the HTML_BBCodeParser script in
the article. Once the class has been included in the script and a new instance of the class started the actual transformation is handled in just one line of code using the transform function. In this way Text_Wiki_BBCode is just as easy to use as HTML_BBCodeParser.
Sadly though this is were the similarities end. Text_Wiki_BBCode is still in alpha version whereas HTML_BBCodeParser is labelled as stable. HTML_BBCodeParser is able to handle a wider selection of BBCode tags and seems to handle them with less problems. Furthermore adding custom BBCode tags to HTML_BBCodeParser seems to be straightforward while it appears to be far from straightforward with Text_Wiki_BBCode.
Overall HTML_BBCodeParser appears to be a far better alternative than Text_Wiki_BBCode when handling BBCode. The only occasion I would consider using Text_Wiki_BBCode would be if I expected my users to primarily submit wiki formatted text, which I would handle with Text_Wiki, and I wanted to also allow them to submit BBcode formatted text. Allowing the user to switch between the two would be very straightforward.