Wu Di's     Resume  |  Portfolio  |  Blog  |  Network  |  Calendar

My Reputation

19 honors

Recent Visitors

Monthly Archive


2010-1 (3)

2009-10 (2)

2009-7 (2)

2009-6 (4)

2009-5 (1)

2009-4 (3)

2009-3 (2)

Categories


Default ( 1 )

linux ( 1 )

ipad ( 1 )

social media marketing ( 1 )

housing ( 1 )

Zeitgeist ( 2 )

funding ( 1 )

flash ( 1 )

javascript ( 1 )

IT business ( 5 )

php ( 2 )

Magento ( 0 )

PHP CSV import/export utf8 issue resolved

By Wu Di on: 2009-10-22 at 12:13:37 | Category: php

non-latin characters exported in utf8 formatted csv files are not recognized by M$ Excel 2007, this is because Excel 2007 doesn't automatically add a BOM into the header of the file when opening it.

What is BOM? Byte Order Mark =>

http://en.wikipedia.org/wiki/Byte-order_mark

How to solve this problem?

VERY SIMPLE!

During Export:

echo chr(239).chr(187).chr(191); 

write this line before you echo the file content and that's it.

 

During Import:

mb_convert_encoding($str,"UTF-8","EUC-CN") 


176 views | 1 comments | Add Comment
By Wu Di on: 2009-10-22 at 16:08:58

note, the above only works for Excel 2007 on Windows... there are some problems on Mac. I managed to find an alternative solution for mac using TSV


Reply
Comment: