Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

token_replace_multiple

Definition

token_replace_multiple($original, $types = array('global' => NULL), $leading = '[', $trailing = ']', $options = array())
contributions/token/token.module, line 183

Description

Return the value of $original, with all instances of placeholder tokens replaced by their proper values. Contrary to token_replace(), this function supports replacing mutiple 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.

Return value

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

Code

<?php
function token_replace_multiple($original, $types = array('global' => NULL), $leading = '[', $trailing = ']', $options = array()) {
  $full = new stdClass();
  $full->tokens = $full->values = array();
  foreach ($types as $type => $object) {
    $temp = token_get_values($type, $object, FALSE, $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);
}
?>