What potential pitfalls should be considered when using PHP to rename directories, especially when dealing with special characters like umlauts?

When renaming directories in PHP, special characters like umlauts can cause issues due to encoding differences. To avoid problems, it is important to properly handle character encoding by using functions like `mb_convert_encoding()` to ensure consistency. Additionally, it is recommended to sanitize user input and validate directory names to prevent any malicious input.

$oldDirName = 'old_directory_name_with_ümläuts';
$newDirName = 'new_directory_name_with_ümläuts';

// Convert directory names to UTF-8 encoding
$oldDirNameUtf8 = mb_convert_encoding($oldDirName, 'UTF-8', 'auto');
$newDirNameUtf8 = mb_convert_encoding($newDirName, 'UTF-8', 'auto');

// Rename directory with sanitized input
if (rename($oldDirNameUtf8, $newDirNameUtf8)) {
    echo "Directory renamed successfully.";
} else {
    echo "Error renaming directory.";
}