Skip to content
PHP Logo

How can Excel compatibility be ensured when writing umlaut characters to a CSV file using PHP?

When writing umlaut characters to a CSV file using PHP, it is important to ensure compatibility with Excel by encoding the file in UTF-8 format. This can be achieved by setting the appropriate headers in the PHP script before writing to the CSV file. By specifying the UTF-8 encoding, Excel will be able to correctly display the umlaut characters without any issues.

php
<?php
header('Content-Encoding: UTF-8');
header('Content-Type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=data.csv');

$data = "Möglichkeit, überprüfen, schön";
$fp = fopen('php://output', 'w');

fputcsv($fp, array($data));

fclose($fp);
?>