You are here

function token_scan in Token 5

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

Build a list of all token-like patterns that appear in the text.

Parameters

$text: The text to be scanned for possible tokens.

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

An array of discovered tokens.

1 call to token_scan()
token_get_invalid_tokens_by_context in ./token.module
Validate an tokens in raw text based on possible contexts.

File

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

Code

function token_scan($text, $leading = TOKEN_PREFIX, $trailing = TOKEN_SUFFIX) {

  // Matches tokens with the following pattern: [$token]
  $leading = preg_quote($leading, '/');
  $trailing = preg_quote($trailing, '/');
  preg_match_all("/{$leading}([^\\s]+?){$trailing}/", $text, $matches);
  return $matches[1];
}