-2

I have a problem with reading csv file.

My task is to import csv file via php. Customer created his csv file in Excel on Mac. This file contains German letters like äüöß. When I open it, that letters are crashed (in all programs of Windows). The only way to reed it correctly is to open file in TextEdit on Mac when system language is set to English (when Russian is set, TextEdit also shows wrong characters).

Example of crashed letters: ナttinger, J゚rgen; Kハthe; Empfハnger

Please help me, I have tried all possible ways to encode the file but no result. mb_detect_encoding shows UTF-8.

How can I read it correctly when I even can't open correctly it on my computer?

Why reading of csv file on Mac depends on system language?

Katya Makeeva
  • 139
  • 1
  • 1
  • 5
  • 1
    Sounds more like a software question rather than a coding question. – apokryfos Jun 14 '17 at 07:56
  • Did you run into a concrete problem importing the file with PHP? UTF-8 is normally well working with PHP, the CSV functions for example can parse UTF-8 encoded CSV file data quite well (one common exception are BOMs which can break the first field / record and need to be filtered out first). To better inspect a CSV file on the desktop, you can try Libre/Open Office, it allows you to inspect the various character encoding settings when opening the file. - See as well: [Which encoding opens CSV files correctly with Excel on both Mac and Windows?](https://stackoverflow.com/q/6588068/367456) – hakre Jun 14 '17 at 08:09
  • See my answer below – Katya Makeeva Jun 14 '17 at 09:16

1 Answers1

0

Solution for me was to add this line:

$line = iconv('macintosh', 'UTF-8', $line);
Katya Makeeva
  • 139
  • 1
  • 1
  • 5