Porblem in UTF-8 support on CSV/EXCEL
Hi,
First Problem:
I have a PHP script that export CSV with Japanese text, for example I download the CSV on the website then save to desktop of my computer and Open it on NOTEPAD... that works fine I could still see all the japanese text OK with no problem, but if I open the CSV file in Microsoft EXCEL, all the japanese text are busted and no longer readable.
Do you know a solution for this, how could I make it work OK on MS Excel, because the user want it to view the CSV file in Excel.
And my second Problem is:
I have another PHP script that export data with Japanese text from database to MS Excel, if I type the Japanese text on the script it works fine but if the text came from database, my problem starts because when i Download and open it in MS Excel the japanese text That I type directly in the script as a header of the excel file is OK but the contents in japanese text populated from the database is not readable in Japanese form....
Do you have any solution for my problem....
Thanks
millanskie
Junior Poster in Training
63 posts since Dec 2006
Reputation Points: 10
Solved Threads: 1
I have the same problems with encoding in a different content - XML files.
For your prob..
Does excel support utf-8 fully?
Question I'm asking myself, how does excel determine encoding?
When saving to the database, is the database data stored as UTF-8?
PHP functions are also non-utf8 aware. For example: strlen() on a UTF-8 string would return the number of bytes in the string, not the number of UTF-8 chars which would be less since a single char is encoded in multiple bytes..
Does your code use some PHP string functions?
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Hi, thanks for the reply. I already found a solution on my problem, I use this kind of php function to solve my problem
$str = mb_convert_encoding($str, "SJIS","UTF-8");
this solve all of my encoding problem....
thanks
millanskie
Junior Poster in Training
63 posts since Dec 2006
Reputation Points: 10
Solved Threads: 1
Awesome.
Just a note: in order to use the function b_convert_encoding, your php installation needs to have the mb_string extension loaded. Not all PHP installations will have this.
I believe there is a sourceforge.net project however that has a mirror of the mb_string functions in PHP.
This will allow you to use the mb_string functions on "any" PHP installation.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101