n_yanev n_yanev - 1 year ago 294
PHP Question

PHP fputcsv encoding

I create csv file with fputcsv. I want csv file to be in windows1251 ecnding. But can't find the solution. How can I do that?

Answer Source

Default encoding for an excel file is machine specific ANSI, mainly windows1252. But since you are creating that file and maybe inserting UTF-8 characters, that file is not going to be handled ok.

You could use iconv() when creating the file. Eg:

function encodeCSV(&$value, $key){
    $value = iconv('UTF-8', 'Windows-1252', $value);
array_walk($values, 'encodeCSV');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download