You are here

function token_clean_token_name in Token 8

Same name and namespace in other branches
  1. 7 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.

File

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

Code

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