protected function cleanFileName($identifier) {

    // Convert or strip certain special characters, by convention.
    $filter = [
      ' ' => '-',
      '_' => '-',
      '/' => '-',
      '[' => '-',
      ']' => '',
    ];
    $identifier = strtr($identifier, $filter);

    // Valid characters in a clean filename identifier are:
    // - the hyphen (U+002D)
    // - the period (U+002E)
    // - 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{002E}\\x{0030}-\\x{0039}\\x{0041}-\\x{005A}\\x{005F}\\x{0061}-\\x{007A}\\x{00A1}-\\x{FFFF}]/u', '', $identifier);

    // Convert everything to lowercase
    return strtolower($identifier);
  }
protected function cleanFileName($identifier) {

    // Convert or strip certain special characters, by convention.
    $filter = [
      ' ' => '-',
      '_' => '-',
      '/' => '-',
      '[' => '-',
      ']' => '',
    ];
    $identifier = strtr($identifier, $filter);

    // Valid characters in a clean filename identifier are:
    // - the hyphen (U+002D)
    // - the period (U+002E)
    // - 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{002E}\\x{0030}-\\x{0039}\\x{0041}-\\x{005A}\\x{005F}\\x{0061}-\\x{007A}\\x{00A1}-\\x{FFFF}]/u', '', $identifier);

    // Convert everything to lowercase
    return strtolower($identifier);
  }
protected function cleanFileName ( $ identifier ) { // Convert or strip certain special characters, by convention. $ filter = [ ' ' => '-' , '_' => '-' , '/' => '-' , '[' => '-' , ']' => '' , ] ; $ identifier = strtr ( $ identifier , $ filter ) ; // Valid characters in a clean filename identifier are: // - the hyphen (U+002D) // - the period (U+002E) // - 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{002E}\\x{0030}-\\x{0039}\\x{0041}-\\x{005A}\\x{005F}\\x{0061}-\\x{007A}\\x{00A1}-\\x{FFFF}]/u' , '' , $ identifier ) ; // Convert everything to lowercase return strtolower ( $ identifier ) ; }
Converts random strings to clean filenames.

The cleanups are loosly based on drupal_clean_css_identifier().
- prefer dash-separated words.
- strip special characters.
- down-case alphabetical letters.
Converts random strings to clean filenames .