Are there any best practices or alternative methods recommended for replacing special characters in file names using PHP?

Special characters in file names can cause issues with file handling in PHP, so it's often necessary to replace them with safe alternatives. One common approach is to use the `preg_replace()` function with a regular expression to match and replace special characters with a specified replacement string.

$filename = "file_with_special@characters.txt";
$clean_filename = preg_replace('/[^\w\d\.-]/', '_', $filename);
echo $clean_filename; // Outputs: file_with_special_characters.txt