1

I'm writing data into a csv that somtimes contains umlauts (äöü). I used:

header('Content-Type: text/csv;charset=UTF-8');

and added on the first line of data

chr(239).chr(187).chr(191)."SEP=\t";

and then filled in the data. However, even so the umlauts get displayed as e.g. Ü for Ü in excel on windows and something similar on mac.

Is there anything I need to do to get this right?

  • Use the correct ASCII table. äöü are produced by Chr(228), Chr(246 and Chr(252). When entering them from a keyboard you can use Alt+0228, 0246 and 0252. – Variatus Apr 13 '21 at 00:00
  • 2
    @Variatus no. Those byte values are for the single-byte ISO8859-1 and cp1252 encodings, _not UTF8_. Simple rule of thumb, if you have a character represented by a single byte with a value above 127, it's not UTF8. – Sammitch Apr 13 '21 at 00:16
  • @Sammitch I don't think OP needs UTF-8 character codes in his application. I think he should use ASCII and the system will convert them to UTF-8. – Variatus Apr 13 '21 at 00:21
  • 1
    @Variatus I don't even know where to start with all of the things wrong with what you've just posted. – Sammitch Apr 13 '21 at 00:28
  • 3
    I've reproduced this locally and the issue seems to be that when Excel sees the `SEP` specification it forgets the charset that it detected when it read the BOM. There are a couple unattractive workarounds [in this question](https://stackoverflow.com/questions/20395699/sep-statement-breaks-utf8-bom-in-csv-file-which-is-generated-by-xsl) but also you could simply use commas or semicolons as separators and skip the `SEP` and this issue altogether. – Sammitch Apr 13 '21 at 00:40
  • @Sammitch when I've used commas word on OS X would properly display the data, but not word on Windows. Another thread suggested tabs as a fix. Also, I can confirm that removing the SEP gets the umlauts right – Pseudo Pseudonym Apr 13 '21 at 07:39
  • Word? You mean Excel, yes? Anyhow, that might be a more solvable issue. I would suggest posting a new question along the lines of "CSV does not display consistently between Excel on Windows and Mac" with example data/code. – Sammitch Apr 13 '21 at 16:55

0 Answers0