You are here

function token_replace_multiple in Token 5

Same name and namespace in other branches
  1. 6 token.module \token_replace_multiple()

Return the value of $original, with all instances of placeholder tokens replaced by their proper values. Contrary to token_replace(), this function supports replacing multiple types.

Parameters

original: A string, or an array of strings, to perform token substitutions on.

types: An array of substitution classes and optional objects. The key is a flag indicating the class of substitution tokens to use. If an object is passed as value, the key should contain the object's type. For example, 'node', 'comment', or 'user'. The object will be used for building substitution values. If no type is specified, only 'global' site-wide substitution tokens are built.

leading: Character(s) to prepend to the token key before searching for matches. Defaults to an open-bracket.

trailing: Character(s) to append to the token key before searching for matches. Defaults to a close-bracket.

flush: A flag indicating whether or not to flush the token cache. Useful for processes that need to slog through huge numbers of tokens in a single execution cycle. Flushing it will keep them from burning through memory. The default is FALSE.

Return value

The modified version of $original, with all substitutions made.

File

./token.module, line 254
The Token API module.

Code

function token_replace_multiple($original, $types = array(
  'global' => NULL,
), $leading = TOKEN_PREFIX, $trailing = TOKEN_SUFFIX, $options = array(), $flush = FALSE) {
  $full = new stdClass();
  $full->tokens = $full->values = array();
  foreach ($types as $type => $object) {
    $temp = token_get_values($type, $object, $flush, $options);
    $full->tokens = array_merge($full->tokens, $temp->tokens);
    $full->values = array_merge($full->values, $temp->values);
  }
  return _token_replace_tokens($original, $full->tokens, $full->values, $leading, $trailing);
}