both:
$result = iconv('UTF-8', 'UTF-16LE//IGNORE//TRANSLIT', $str);
and mb_convert_encoding() fail to convert a ndash (–) the long minus.
The result will go into a csv, so replacing it with an html entity is not an option. Any ideas?
code:
$data = $eventHelper->getProgramForCsvExport($event);
$response = new StreamedResponse();
$response->setCharset('UTF-16LE');
$filename = 'program-' . $event->getShortName() . $event->getShortYear() . '.csv';
$utf16Data = [];
foreach ($data as $row) {
$utf16row = [];
foreach ($row as $entry) {
$utf16row[] = iconv('UTF-8', 'UTF-16LE//IGNORE//TRANSLIT', $entry);
}
$utf16Data[] = $utf16row;
}
$response->setCallback(function () use ($utf16Data) {
$output = fopen('php://output', 'w+');
foreach ($utf16Data as $row) {
fputcsv($output, $row, ';');
}
fclose($output);
});
$response->headers->set('Content-Type', 'text/csv; charset=utf-16');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
Edit: It's an export for the great office 365 which doesn't support UTF-8 anymore but is on UTF-16LE on default (as far as I read). German umlauts (äöüß) work fine (and didn't before the convert), but ndash (and maybe some other special chars) don't. Ndashes are either blank (on mac) or become brackets (or so) on windows.