Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn how to export csv data. Thinkphp is usually used to process data, but the code is similar to the following code logic! Does not rely on any third-party class libraries
// Data Processing
Function exportData (){
$ Result = mysql_query ("select * from student ");
$ Str = "name, gender, age \ n ";
$ Str = iconv ('utf-8', 'gb2312', $ str );
While ($ row = mysql_fetch_array ($ result )){
$ Name = iconv ('utf-8', 'gb2312', $ row ['name']);
$ Sex = iconv ('utf-8', 'gb2312', $ row ['sex']);
$ Str. = $ name. ",". $ sex. ",". $ row ['age']. "\ n ";
}
$ Filename = date('ymd'0000.'.csv ';
Export_csv ($ filename, $ str );
}
// Output
Function export_csv ($ filename, $ data ){
Header ("Content-type: text/csv ");
Header ("Content-Disposition: attachment; filename =". $ filename );
Header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 ');
Header ('expires: 0 ');
Header ('pragma: public ');
Echo $ data;
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB