When creating a CSV file with the special characters, be sure to encounter the problem of encoding characters. Although the output is in UTF-8 OK, Microsoft Excel displays the wrong characters. The solution is simple and is called BOM. At the beginning of the file just add the BOM characters, indicating that the file is in the character set UTF-8.
Solution:
$ document = chr (0xEF). chr (0xBB). chr (0xBF). $ csvContent;
Variable csvContent contains the contents of the CSV document. The variable document is a content of CSV dates, you just need to write to a file.