You are here

function token_clean_token_name in Token 7

Same name and namespace in other branches
  1. 8 token.module \token_clean_token_name()

Prepare a string for use as a valid token name.

Parameters

$name: The token name to clean.

Return value

The cleaned token name.

1 call to token_clean_token_name()
_token_profile_fields in ./token.tokens.inc
Fetch an array of profile field objects, keyed by token name.

File

./token.module, line 1147
Enhances the token API in core: adds a browseable UI, missing tokens, etc.

Code

function token_clean_token_name($name) {
  static $names = array();
  if (!isset($names[$name])) {
    $cleaned_name = strtr($name, array(
      ' ' => '-',
      '_' => '-',
      '/' => '-',
      '[' => '-',
      ']' => '',
    ));
    $cleaned_name = preg_replace('/[^\\w\\-]/i', '', $cleaned_name);
    $cleaned_name = trim($cleaned_name, '-');
    $names[$name] = $cleaned_name;
  }
  return $names[$name];
}