Featured Utf8 Csv

Have you ever generated a CSV file using PHP and found some characters looking not quite the same as in the original data, for example apostrophes?

The reason it happens is the encoding. Your data can be in UTF-8 but default spreadsheet editor’s (Excel for example) could be something else. This will cause the characters in UTF-8 not to be rendered correctly.

The fix this the CSV output needs to be prepended with three bytes (called BOM – Byte Order Mark) to tell the spreadsheet editor about the encoding. Please see code example below:

Original information was partially sourced from http://www.skoumal.net/en/making-utf-8-csv-excel/

Anton Zaroutski

WordPress Specialist, Front End and PHP Developer, @xeiter

Leave a Reply

Your email address will not be published. Required fields are marked *