PHP's own function fputcsv can be used to print the report (Excel) function. If your report format requirements are not very high, then fputcsv is a good choice. It performs efficiently and does not require a third-party library, which is convenient to use.
The above code will generate a CSV file locally, can be opened in Excel, is not very simple. If there is Chinese, after Linux execution, download to the local open will be garbled, then you can use the Iconv function to convert.
$list = Array ();
$tmp = "Order number, order payment amount, lucky number, user name, user type, period, number generation time, draw time, award logo, Prize, bonus, notes";
$list [] = Iconv (' UTF-8 ', ' Gb2312//ignore ', $tmp);
Export the generated CSV directly to the browser
Header (' content-disposition:attachment; filename=contacts.csv ');//If the file name is in Chinese, the UrlEncode will not appear in IE after the Chinese characters.
Header (' Content-type:application/octet-stream ');
Header (' Content-length: '. FileSize (' contacts.csv '));//File size
ReadFile ($file _path);
Exit ();
Second, import the report with Fgetcsv
There is a point to be aware of when importing reports with Fgetcsv. It is necessary to convert the EXCEL document into CSV format. Note: It is not easy to change the suffix name.