Re: new class proposal: UBB tag parser

From: Date: Sun, 08 Dec 2002 14:41:01 +0000
Subject: Re: new class proposal: UBB tag parser
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-11434@lists.php.net to get a copy of this message
Stijn de Reede wrote:
Hi all, About a year ago I wrote a stack based parser for ubb like tags. Running text through this parser replaces [b], [u], [url] etc with their html equivalents. This can be useful if you want to give users some control over the text layout, but don't want to allow users to post html as they can break your site (with div's etc). Note that this is not just a collection of regular expressions, but this class builds an array from the input text and validates each tag and it's nesting. It should only produce xhtml 1.0 compliant code. Up until now I've never released my source code, but I think PEAR is such a great project that I want to do something in return. So I rewrote the collection of funtions a had to a class with method's, that can easily be extended. You will see that the class is pretty good documented, so you can see in the source code how it works. Here's a short example on how you would use the class: --------------- require_once('HTML/Parser/SimpleTags.php'); $config = parse_ini_file('SimpleTags.ini', true); $options = &PEAR::getStaticProperty('HTML_Parser_SimpleTags', '_options'); $options = $config['HTML_Parser_SimpleTags']; unset($options); $parser = new HTML_Parser_SimpleTags(); $parser->setText('normal [b]bold[/b] and normal again'); parser->parse(); echo $parser->getParsed(); // or: $parser = new HTML_Parser_SimpleTags(); echo $parser->qparse('normal [b]bold[/b] and normal again'); // or: echo HTML_Parser_SimpleTags::staticQparse('normal [b]bold[/b] and normal again'); --------------- A working example can be found here: http://sjr.dyndns.org/parser/parser.php (see this site for examples on the current tags it is able to parse) And the source code: http://sjr.dyndns.org/parser/HTML_Parser_SimpleTags.tgz I'm not sure yet about the name it should have, and if it should be in it's own subdir (Parser). Maybe it should be something like HTML/UbbTagParser.php, but I don't know if I'm allowed to use UBB in it's name. If you think this is a good addition for PEAR, then I will gladly commit to CVS and eventually package it.
+1 , havent looked at the code (trust others to do so), think you can always say UBB compat, maybe credit UBB for their trademark if any, good work. Maarten

« previous php.pear.dev (#11434) next »