You are here

function token_replace in Token 5

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

Return the value of $original, with all instances of placeholder tokens replaced by their proper values. To replace multiple types at once see token_replace_multiple().

Parameters

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

type: A flag indicating the class of substitution tokens to use. If an object is passed in the second param, 'type' should contain the object's type. For example, 'node', 'comment', or 'user'. If no type is specified, only 'global' site-wide substitution tokens are built.

object: Optionally, the object to use for building substitution values. A node, comment, user, etc.

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 219
The Token API module.

Code

function token_replace($original, $type = 'global', $object = NULL, $leading = TOKEN_PREFIX, $trailing = TOKEN_SUFFIX, $options = array(), $flush = FALSE) {
  $full = token_get_values($type, $object, $flush, $options);
  return _token_replace_tokens($original, $full->tokens, $full->values, $leading, $trailing);
}