function views_clean_css_identifier

Prepare a string for use as a valid CSS identifier.

This function is similar to a core version but with more intuitive filter values. http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid CSS identifiers (including element names, classes, and IDs in selectors).

Parameters

string $identifier: The identifier to clean.

array $filter: An array of string replacements to use on the identifier.

Return value

string The cleaned identifier.

See also

drupal_clean_css_identifier()

3 calls to views_clean_css_identifier()
views_handler_field::element_classes in handlers/views_handler_field.inc
Return the class of the field.
views_handler_field::element_label_classes in handlers/views_handler_field.inc
Return the class of the field's label.
views_handler_field::element_wrapper_classes in handlers/views_handler_field.inc
Return the class of the field's wrapper.
2 string references to 'views_clean_css_identifier'
template_preprocess_views_view_list in theme/theme.inc
Display the view as an HTML list element.
template_preprocess_views_view_table in theme/theme.inc
Display a view as a table style.

File

./views.module, line 2612

Code

function views_clean_css_identifier($identifier, $filter = array(
    ' ' => '-',
    '/' => '-',
    '[' => '-',
    ']' => '',
)) {
    // By default, we filter using Drupal's coding standards.
    $identifier = strtr($identifier, $filter);
    // Valid characters in a CSS identifier are:
    // - the hyphen (U+002D)
    // - a-z (U+0030 - U+0039)
    // - A-Z (U+0041 - U+005A)
    // - the underscore (U+005F)
    // - 0-9 (U+0061 - U+007A)
    // - ISO 10646 characters U+00A1 and higher
    // We strip out any character not in the above list.
    $identifier = preg_replace('/[^\\x{002D}\\x{0030}-\\x{0039}\\x{0041}-\\x{005A}\\x{005F}\\x{0061}-\\x{007A}\\x{00A1}-\\x{FFFF}]/u', '', $identifier);
    return $identifier;
}