0

We have a PHP application running on Apache which generates CSV files that are to be opened with Excel; the content is encoded in UTF-8. However, there is a problem with Excel, which does not recognise the character encoding and displays the annoying 'ö' instead of 'ö', for example, as described in this question.

Now, since it is not possible to configure Excel to correctly recognise UTF-8 encoding, and opening the file through 'external data import' as described in this answer is not an acceptable for us, I thought maybe it is possible to configure Apache to use some kind of filter to convert UTF-8 encoded response to ISO 8859-1 on the fly? In this case I would not have to change any PHP scripts - they would continue to produce UTF-8 encoded content - I would just have to configure Apache to convert the output for some of them to ISO 8859-1 on the fly such that the resulting files could be opened easily with Excel.

Community
  • 1
  • 1
proskor
  • 1,342
  • 8
  • 20

1 Answers1

1

Actually solved it with this:

# beginning of file
function encode($buffer) {
    return iconv("UTF-8", "ISO-8859-1", $buffer);
}

ob_start("encode");

# content generated here

ob_end_flush();
# end of file
proskor
  • 1,342
  • 8
  • 20