function callback_filter_prepare

7.x filter.api.php callback_filter_prepare($text, $filter, $format, $langcode, $cache, $cache_id)

Provide prepared text with special characters escaped.

Callback for hook_filter_info().

See hook_filter_info() for a description of the filtering process. Filters should not use the 'prepare callback' step for anything other than escaping, because that would short-circuit the control the user has over the order in which filters are applied.

Parameters

$text: The text string to be filtered.

$filter: The filter object containing settings for the given format.

$format: The text format object assigned to the text to be filtered.

$langcode: The language code of the text to be filtered.

$cache: A Boolean indicating whether the filtered text is going to be cached in {cache_filter}.

$cache_id: The ID of the filtered text in {cache_filter}, if $cache is TRUE.

Return value

The prepared, escaped text.

Related topics

File

drupal-7.x/modules/filter/filter.api.php, line 203
Hooks provided by the Filter module.

Code

function callback_filter_prepare($text, $filter, $format, $langcode, $cache, $cache_id) {
  // Escape <code> and </code> tags.
  $text = preg_replace('|<code>(.+?)</code>|se', "[codefilter_code]$1[/codefilter_code]", $text);
  return $text;
}