fputcsv - outputs norwegian characters as question marks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
markjohnson
Forum Newbie
Posts: 15
Joined: Sat Feb 07, 2009 8:36 pm

fputcsv - outputs norwegian characters as question marks

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: fputcsv - outputs norwegian characters as question marks

Post 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()?
(#10850)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: fputcsv - outputs norwegian characters as question marks

Post by requinix »

Can you post the entire code? Everything from where you set the street_address to where you output it to the file.
Post Reply