In addition to the parser functions the class also provides so-called filters. Filters are functions that have to behave the same as parser functions. They have to accept a text as the only parameter and return a string. The class knows of two different filter types:
- These are filters that are called before the parsing process. The complete text that is to be parsed is passed through every filter and is processed not until then.
- These are filters that are called after the tree has been converted to a string again and just before the
parsemethod returns the text.
Filters are defined similar to parser functions:
$bbcode->addFilter (STRINGPARSER_FILTER_PRE, 'my_filter_function');
$bbcode->addFilter (STRINGPARSER_FILTER_POST, 'my_second_filter_function');
STRINGPARSER_FILTER_POST are important here.
STRINGPARSER_FILTER_PRE indicates that the filter is a prefilter,
STRINGPARSER_FILTER_POST that it is a postfilter.
Exactly as with parser functions filters may also be class methods:
$bbcode->addFilter (STRINGPARSER_FILTER_PRE, array (&my_object, 'my_method'));