2

I want to export a mysql database, which contains Chinese Characters, to a csv file. The original encoding of the mysql data is UTF-8, but when I export it to csv, the excel cannot display the chinese character. I know the problem is that I need to add BOM the encoding, I have follow the steps people taught but it doesn't work. May I ask anyone can help. please?? This the code I have:`

header("Content-type:text/csv; charset=utf-8-sig"); 
header("Content-Disposition:attachment;filename=".$v_scrn.".csv"); 
header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); 
header('Expires:0'); 
header('Pragma:public'); 
echo "\xEF\xBB\xBF";
echo $data;
pnuts
  • 58,317
  • 11
  • 87
  • 139
  • The first echo produces the correct UTF-8 BOM. I have never seen `charset=utf-8-sig`, always just `charset=utf-8`. In which way is your code broken? What does not work for you? – Palec Jan 07 '14 at 02:36
  • You may also want to [convert your data from UTF-8 to UTF-16LE](http://stackoverflow.com/a/4762708/570812). – Passerby Jan 07 '14 at 03:44
  • I have tried UTF-8, UTF-16LE, but none works...I have no idea which part went wrong, just I can't see the Chinese characters displayed. – user3167515 Jan 07 '14 at 03:53
  • To clarify, the csv is successfully exported, when I open in Notepad++, it tells me that it is encoded with UTF-8 WITHOUT BOM, even though I have already add [echo "\xEF\xBB\xBF";] this line...Please may someone tell me why???? THANKS! – user3167515 Jan 07 '14 at 04:31
  • OHH I found out what's wrong! I have to put the [echo "\xEF\xBB\xBF";] at the very beginning of the code, just after – user3167515 Jan 07 '14 at 04:44

0 Answers0