function token_find_with_prefix
7.x token.inc | token_find_with_prefix(array $tokens, $prefix, $delimiter = ':') |
Returns a list of tokens that begin with a specific prefix.
Used to extract a group of 'chained' tokens (such as [node:author:name]) from the full list of tokens found in text. For example:
$data = array(
'author:name' => '[node:author:name]',
'title' => '[node:title]',
'created' => '[node:created]',
);
$results = token_find_with_prefix($data, 'author');
$results == array('name' => '[node:author:name]');
Parameters
$tokens: A keyed array of tokens, and their original raw form in the source text.
$prefix: A textual string to be matched at the beginning of the token.
$delimiter: An optional string containing the character that separates the prefix from the rest of the token. Defaults to ':'.
Return value
An associative array of discovered tokens, with the prefix and delimiter stripped from the key.
7 calls to token_find_with_prefix()
- comment_tokens in drupal-7.x/
modules/ comment/ comment.tokens.inc - Implements hook_tokens().
- hook_tokens in drupal-7.x/
modules/ system/ system.api.php - Provide replacement values for placeholder tokens.
- node_tokens in drupal-7.x/
modules/ node/ node.tokens.inc - Implements hook_tokens().
- statistics_tokens in drupal-7.x/
modules/ statistics/ statistics.tokens.inc - Implements hook_tokens().
- system_tokens in drupal-7.x/
modules/ system/ system.tokens.inc - Implements hook_tokens().
File
- drupal-7.x/
includes/ token.inc, line 219 - Drupal placeholder/token replacement system.
Code
function token_find_with_prefix(array $tokens, $prefix, $delimiter = ':') {
$results = array();
foreach ($tokens as $token => $raw) {
$parts = explode($delimiter, $token, 2);
if (count($parts) == 2 && $parts[0] == $prefix) {
$results[$parts[1]] = $raw;
}
}
return $results;
}