You are here

function _lexicon_create_valid_id in Lexicon 7

Same name and namespace in other branches
  1. 6 lexicon.module \_lexicon_create_valid_id()

Function that resturns a valid id to be used as anchor-id based on the name that is supplied to the function.

3 calls to _lexicon_create_valid_id()
_filter_lexicon_process in ./lexicon.module
Lexicon filter process callback function. Marks terms in the content of the website.
_lexicon_overview in includes/lexicon.pages.inc
Lexicon overview function that creates all the data end renders the output through the various theme templates.
_lexicon_term_add_info in ./lexicon.module
Lexicon function to add extra information to a term object.

File

./lexicon.module, line 1303
The Lexicon module is used to create lists of terms and definitions to use on a website and optionally mark those terms in the content of the website.

Code

function _lexicon_create_valid_id($name) {
  $allowed_chars = '-A-Za-z0-9._:';
  $id = preg_replace(array(
    '/ |\\s/',
    '/\'/',
    '/—/',
    '/&/',
    '/&[a-z]+;/',
    '/[^' . $allowed_chars . ']/',
    '/^[-0-9._:]+/',
    '/__+/',
  ), array(
    //   and spaces.
    '_',
    // apostrophe, so it makes things slightly more readable.
    '-',
    // —.
    '--',
    // &.
    'and',
    // Any other entity.
    '',
    // Any character that is invalid as an ID name.
    '',
    // Any digits at the start of the name.
    '',
    // Reduce multiple underscores to just one.
    '_',
  ), strip_tags($name));
  return $id;
}