token_replace($text, array $data = array(), array $options = array())Replace all tokens in a given string with appropriate values.
$text A string potentially containing replaceable tokens.
$data (optional) An array of keyed objects. For simple replacement scenarios 'node', 'user', and others are common keys, with an accompanying node or user object being the value. Some token types, like 'site', do not require any explicit information from $data and can be replaced even if it is empty.
$options (optional) A keyed array of settings and flags to control the token replacement process. Supported options are:
Text with tokens replaced.
includes/token.inc, line 76
<?php
function token_replace($text, array $data = array(), array $options = array()) {
$replacements = array();
foreach (token_scan($text) as $type => $tokens) {
$replacements += token_generate($type, $tokens, $data, $options);
if (!empty($options['clear'])) {
$replacements += array_fill_keys($tokens, '');
}
}
// Optionally alter the list of replacement values.
if (!empty($options['callback']) && function_exists($options['callback'])) {
$function = $options['callback'];
$function($replacements, $data, $options);
}
$tokens = array_keys($replacements);
$values = array_values($replacements);
return str_replace($tokens, $values, $text);
}
?>