5. Filters
5.1 Filter types
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:
- Prefilters
- 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.
- Postfilters
- These are filters that are called after the tree has been converted to a string again and just before the
parse
method returns the text.
5.2 Defining filters
Filters are defined similar to parser functions:
$bbcode->addFilter (STRINGPARSER_FILTER_PRE, 'my_filter_function');
$bbcode->addFilter (STRINGPARSER_FILTER_POST, 'my_second_filter_function');
The constants STRINGPARSER_FILTER_PRE
and 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'));
- Weiter: 6. Flags to control the behaviour of the class
- Zurück: 4. Callback functions