What are common issues when replacing special characters like umlauts in PHP filenames?

When replacing special characters like umlauts in PHP filenames, a common issue is that the resulting filename may not be valid or may conflict with existing filenames. To solve this, you can replace umlauts with their corresponding ASCII characters or remove them entirely. Additionally, you can check for filename validity before renaming the file.

$filename = "fünf.txt";
$filename = str_replace(['ä', 'ö', 'ü', 'ß'], ['ae', 'oe', 'ue', 'ss'], $filename);
$filename = preg_replace('/[^a-zA-Z0-9_.-]/', '', $filename);
// Check for filename validity here
rename("original/fünf.txt", "target/" . $filename);