1

i am creating csv files with php. To write the data into my csv file, i use the php function "fputcsv".

this is the issue: i can open the created file normally with Excel. But i cant import the file into a shopsystem (in this case "shopware"). It says something like "the data could not be read".

And now comes the clue:

If i open the created file and choose "save as" and select "CSV (comma delimited)" in type, this file can be imported into shopware. I read something about the php function "mb_convert_encoding" which i used to encode the data, but it could not fix the problem.

I will be very glad if you can help me.

thanks.

sentinel777
  • 129
  • 2
  • 4
  • 11

3 Answers3

1

Thanks for your input. I solved this problem by replacing fputcsv with fwrite. Then i just needed to add "\r\n" (thanks wmil) to the end of the line and the generated file can be read by shopware.

Obviously the fputcsv function uses \n and not \r\n as EOL character.

sentinel777
  • 129
  • 2
  • 4
  • 11
0

I think you cannot set the encode using fputcsv. However fputcsv looks to the locale setting, wich you can change with setlocale.

Maybe you could send your file directly to the users browser and use changing contenttype and charset with header function.

woozy
  • 148
  • 7
  • i am not setting the encode type with fputcsv. i just encode the values of the input array, which fputcsv takes as an argument. the file is not for download, but for a cronjob, which initiates the import into shopware. – sentinel777 Oct 27 '11 at 11:04
0

This can't be answered without knowing more about your system. Most likely it has nothing to do with character encoding. It's probably a problem with wrong number of columns or column headers being incorrect.

If it is a character encoding issue, your best bet is:

$new_str = mb_convert_encoding($str, 'Windows-1252', 'auto');

Also end newlines with \r\n, not just \n.

If that doesn't work you'll need to check the software docs.

wmil
  • 3,179
  • 2
  • 21
  • 24
  • the numbers of columns are correct in each row, i just verified. unfortunately the suggested encoding did not solve the problem. i have no influence on the EOL character since it is written automatically by fputcsv. which software docs do you mean? – sentinel777 Oct 27 '11 at 10:16