1){ $ext = end($filename_parts); // Replace all weird characters $sanitized = substr($filename, 0, -(strlen($ext)+1)); $sanitized = str_replace(".", "willbedots", $sanitized); $sanitized = str_replace("_", "willbetrimmed", $sanitized); $sanitized = sanitize_file_name($sanitized); $sanitized = str_replace("willbetrimmed", "_", $sanitized); $sanitized = str_replace("willbedots", ".", $sanitized); // Replace dots inside filename //$sanitized = str_replace('.','-', $sanitized); return $sanitized . '.' . $ext; } return $filename; }