Small example of php export (generate) CSV file
- /**
- * Generate CSV files separated by commas by default.
- * Solution: the content contains commas (,) and double quotation marks ("")
- * @ Author zf Edit: bbs.it-home.org
- * @ Version 2012-11-14
- */
- Header ("Content-Type: application/vnd. ms-excel; charset = GB2312 ");
- Header ("Content-Disposition: attachment?filename=csvdata .csv ");
-
- $ Rs = array (
- Array ('A', "I'm li lei", '"boy"', '¥122,300.00 '),
- Array ('CC', 'I \'m han mei',' "gile" ',' ¥122,500.00 '),
- );
- $ Str = '';
- Foreach ($ rs as $ row ){
- $ Str_arr = array ();
- Foreach ($ row as $ column ){
- $ Str_arr [] = '"'. str_replace ('"', '"', $ column ).'"';
- }
- $ Str. = implode (',', $ str_arr). PHP_EOL;
- }
- Echo $ str;
Note: You must pay attention to the encoding when exporting csv files in php. >>> For more information about exporting csv files from php. |