Fputcsv - outputs norwegian characters as question marks

Hi,

I have a string variable:

$billing['street_address'] = "Præstelængen";

It is in UTF-8:

dd(mb_detect_encoding ($billing['street_address']));

// UTF-8

I do the following to make a CSV file:

($billing is now part of $OrderData array)

$fp = fopen($filename, 'w');
 foreach ($OrderData as $records) {
 fputcsv($fp, $records);
}
fclose($fp);

The string comes out in the csv file as: Pr?stel?ngen

Googling around I saw some point to this:

fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));

But it didn’t work for me. It gives me ? in diamonds instead.

Any ideas?

Have you tried to convert to UTF-16

$fp = fopen($filename, 'w');
fwrite($fp, chr(255).chr(254));

foreach ($OrderData as $records) {
$records = mb_convert_encoding($records, 'UTF-16LE', 'UTF-8');
 fputcsv($fp, $records);
}
fclose($fp);

This article contains IPA phonetic symbols. Without proper rendering support, you may see question marks, boxes, or other symbols instead of Unicode characters.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.