How can the encoding of umlaut characters be managed when writing to a CSV file in PHP?
When writing umlaut characters to a CSV file in PHP, it is important to ensure that the encoding is properly managed to avoid any issues with character representation. One way to handle this is by using the `utf8_encode()` function to convert the characters to UTF-8 encoding before writing them to the file.
// Sample code to write umlaut characters to a CSV file with proper encoding management
$data = ["Möller", "Schön", "Über"];
$file = fopen('output.csv', 'w');
foreach ($data as $row) {
fputcsv($file, array_map('utf8_encode', [$row]));
}
fclose($file);