function transliteration_clean_filename in Transliteration 6.2
Same name and namespace in other branches
- 5.2 transliteration.inc \transliteration_clean_filename()
- 5 transliteration.inc \transliteration_clean_filename()
- 6.3 transliteration.module \transliteration_clean_filename()
- 6 transliteration.inc \transliteration_clean_filename()
- 7.3 transliteration.module \transliteration_clean_filename()
Sanitize a file name.
Transliterates the file name and removes invalid characters.
Parameters
$filename: A file name.
$source_langcode: Optional ISO 639 language code that denotes the language of the input. Used to apply language-specific variations and defaults to the current display language. If transliteration takes place during output (instead of creation) and the source language is not known at that time, it is recommended to set this argument to 'en' to produce consistent results for all enabled languages.
Return value
Cleaned file name.
2 calls to transliteration_clean_filename()
- transliteration_init in ./
transliteration.module - Implementation of hook_init().
- transliteration_install_retroactive in ./
transliteration.install - Helper function; retroactivly transliterate existing file names.
File
- ./
transliteration.inc, line 20
Code
function transliteration_clean_filename($filename, $source_langcode = NULL) {
// Trim any leading/trailing dots.
$filename = trim($filename, '.');
// Transliterate to ASCII.
$filename = transliteration_process($filename, '', $source_langcode);
// Replace whitespace.
$filename = str_replace(' ', '_', $filename);
// Remove any remaining non-safe characters.
$filename = preg_replace('/[^0-9A-Za-z_.-]/', '', $filename);
// Force lowercase to prevent issues on case insensitive file systems.
$filename = strtolower($filename);
return $filename;
}