Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.
// Sanitize filename by replacing international characters with underscores
function sanitize_filename($str, $is_file = false) {
global $config;
// Allow only alphanumeric characters, hyphen, and dot in file names
// Spaces will be changed to dashes, special chars will be suppressed, & the rest will be replaced with underscores
$special_chars = array ('#', '$', '%', '^', '&', '*', '!', '~', '"', '\'', '=', '?', '/', '[', ']', '(', ')', '|', '<', '>', ';', ':', '\\', ', ');
$str = str_replace($special_chars, '', $str);
$str = str_replace(' ', '-', $str);
// urlencode the string to get the url escaped equivalent
$str = urlencode($str);
// change the percentages to hyphens
$str = str_replace('%', '-', $str);
// drop any additional characters (should be nothing, but just in case)
$str = preg_replace("/[^a-zA-Z0-9\-\.]/", '', $str);
// remove any double hyphens from the string
$str = str_replace('--', '-', $str);
if ($is_file && intval($config['truncate']) > 0 && isset($str{intval($config['truncate'])})) {
$str = substr($str, 0, intval($config['truncate']));
}
return $str;
}
1 to 5 of 5