Page 1 of 1

fputcsv - outputs norwegian characters as question marks

Posted: Wed Apr 15, 2015 9:12 am
by markjohnson
Hi,

I have a string variable:

Code: Select all

$billing['street_address'] = "Præstelængen";
It is in UTF-8:

Code: Select all

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)

Code: Select all

$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:

Code: Select all

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

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

Any ideas?

Re: fputcsv - outputs norwegian characters as question marks

Posted: Wed Apr 15, 2015 2:26 pm
by Christopher
markjohnson wrote: Googling around I saw some point to this:

Code: Select all

fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
That is the Byte Order Mark (BOM) for UTF-8. You can also just do echo "\xEF\xBB\xBF"; I don't think that will help for CSV files. Have you tried iconv()?

Re: fputcsv - outputs norwegian characters as question marks

Posted: Wed Apr 15, 2015 2:38 pm
by requinix
Can you post the entire code? Everything from where you set the street_address to where you output it to the file.