HTML_BBCodeParser2
[ class tree: HTML_BBCodeParser2 ] [ index: HTML_BBCodeParser2 ] [ all elements ]

Class: HTML_BBCodeParser2

Source Location: /HTML_BBCodeParser2-0.1.0/HTML/BBCodeParser2.php

Class Overview




Author(s):

  • Stijn de Reede <sjr at gmx.co.uk>

    This is a parser to replace UBB style tags with their html equivalents. It does not simply do some regex calls, but is complete stack based parse engine. This ensures that all tags are properly nested, if not, extra tags are added to maintain the nesting. This parser should only produce xhtml 1.0 compliant code. All tags are validated and so are all their attributes. It should be easy to extend this parser with your own tags, see the _definedTags format description below.

    Usage: $parser = new HTML_BBCodeParser2($options = array(...)); $parser->setText('normal [b]bold[/b] and normal again'); $parser->parse(); echo $parser->getParsed(); or: $parser = new HTML_BBCodeParser2($options = array(...)); echo $parser->qparse('normal [b]bold[/b] and normal again'); or: echo HTML_BBCodeParser2::staticQparse('normal [b]bold[/b] and normal again');

    Setting the options from the ini file: $config = parse_ini_file('BBCodeParser.ini', true); $options = $config['HTML_BBCodeParser2'];

    The _definedTags variables should be in this format: array('tag' // the actual tag used => array('htmlopen' => 'open', // the opening tag in html 'htmlclose' => 'close', // the closing tag in html, can be set to an empty string if no closing tag is present in html (like <img>) 'allowed' => 'allow', // tags that are allowed inside this tag. Values can be all or none, or either of these two, followed by a ^ and then followed by a comma seperated list of exceptions on this 'attributes' => array() // an associative array containing the tag attributes and their printf() html equivalents, to which the first argument is the value, and the second is the quote. Default would be something like this: 'attr' => 'attr=%2$s%1$s%2$s' ), 'etc' => (...) )

Methods


Child classes:

HTML_BBCodeParser2_Filter
Dummy class that filters need to extend from.

Inherited Variables

Inherited Methods


Class Details

[line 78]
  • Author:

    Stijn de Reede <sjr@gmx.co.uk>

    This is a parser to replace UBB style tags with their html equivalents. It does not simply do some regex calls, but is complete stack based parse engine. This ensures that all tags are properly nested, if not, extra tags are added to maintain the nesting. This parser should only produce xhtml 1.0 compliant code. All tags are validated and so are all their attributes. It should be easy to extend this parser with your own tags, see the _definedTags format description below.

    Usage: $parser = new HTML_BBCodeParser2($options = array(...)); $parser->setText('normal [b]bold[/b] and normal again'); $parser->parse(); echo $parser->getParsed(); or: $parser = new HTML_BBCodeParser2($options = array(...)); echo $parser->qparse('normal [b]bold[/b] and normal again'); or: echo HTML_BBCodeParser2::staticQparse('normal [b]bold[/b] and normal again');

    Setting the options from the ini file: $config = parse_ini_file('BBCodeParser.ini', true); $options = $config['HTML_BBCodeParser2'];

    The _definedTags variables should be in this format: array('tag' // the actual tag used => array('htmlopen' => 'open', // the opening tag in html 'htmlclose' => 'close', // the closing tag in html, can be set to an empty string if no closing tag is present in html (like <img>) 'allowed' => 'allow', // tags that are allowed inside this tag. Values can be all or none, or either of these two, followed by a ^ and then followed by a comma seperated list of exceptions on this 'attributes' => array() // an associative array containing the tag attributes and their printf() html equivalents, to which the first argument is the value, and the second is the quote. Default would be something like this: 'attr' => 'attr=%2$s%1$s%2$s' ), 'etc' => (...) )



[ Top ]


Method Detail

__construct (Constructor)   [line 157]

none __construct( [array $options = array()])

Constructor, initialises the options and filters

Sets options to properly escape the tag characters in preg_replace() etc.

All the filters in the options are initialised and their defined tags are copied into the private variable _definedTags.


Parameters:

array   $options     options to use, can be left out

[ Top ]

addFilter   [line 208]

void addFilter( string $filter)

Add a new filter

Parameters:

string   $filter     filter

[ Top ]

addFilters   [line 255]

boolean addFilters( mixed $filters)

Add new filters

Parameters:

mixed   $filters     (array or string)

[ Top ]

getParsed   [line 808]

string getParsed( )

Gets the parsed text from the object

[ Top ]

getPreparsed   [line 794]

string getPreparsed( )

Gets the preparsed text from the object
  • Return: the text set in the object
  • Author: Stijn de Reede <sjr@gmx.co.uk>
  • See: $_preparsed
  • See: _preparse()
  • Access: public

[ Top ]

getText   [line 780]

string getText( )

Gets the unparsed text from the object

[ Top ]

parse   [line 824]

none parse( )

Parses the text set in the object
  • Author: Stijn de Reede <sjr@gmx.co.uk>
  • See: _buildParsedString()
  • See: _validateTagArray()
  • See: _buildTagArray()
  • See: _preparse()
  • Access: public

[ Top ]

qparse   [line 841]

none qparse( $str)

Quick method to do setText(), parse() and getParsed at once

Parameters:

   $str     

[ Top ]

removeFilter   [line 231]

void removeFilter( string $filter)

Remove an existing filter

Parameters:

string   $filter     

[ Top ]

setOption   [line 197]

void setOption( string $name, mixed $value)

Option setter

Parameters:

string   $name     option name
mixed   $value     option value

[ Top ]

setText   [line 766]

none setText( string $str)

Sets text in the object to be parsed

Parameters:

string   $str     the text to set in the object

[ Top ]

staticQparse   [line 857]

none staticQparse( $str)

Quick static method to do setText(), parse() and getParsed at once

Parameters:

   $str     

[ Top ]


Documentation generated on Sat, 03 Nov 2012 14:30:03 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.