Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

utf 8 - php header excel and utf-8

ob_start();

echo 'Dés?àui';

header("Content-Type:   application/vnd.ms-excel; charset=utf-8");
header("Content-type:   application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=Test.xls"); 
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); 

ob_end_flush();

What I'm getting in the excel file is D??s?§??ui

However, I do get Dés?àui when I try

ob_start();
echo 'Dés?àui';
header("Content-Type:   text/html; charset=utf-8");
ob_end_flush();

Any help experts?

PS. The file is saved in DW with Title/Encoding Unicode(Utf-8).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Source http://www.mwasif.com/2007/5/download-data-csv-using-php/

Solution worked for me

Danish Zahur said,

October 7, 2009 @ 7:23 pm

If your contents are in UTF-8 format, then no need to convert encoding. Just start your file/output stream with UTF-8 BOM after headers.

echo pack("CCC",0xef,0xbb,0xbf);

And header should contain encoding UTF-8

header( "Content-type: application/vnd.ms-excel; charset=UTF-8" );

It will work like charm because Excel will recognize file charset with BOM bytes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...