-
-
- /**
- * Generate CSV files separated by commas by default
- * Solution: The content contains commas (,), double quotes ("")
- * @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=CSV data.csv ");
-
- $rs = array(
- array('aa', "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;
Copy code
Note: Sometimes it is important to pay attention to the encoding issues when exporting csv files with PHP.
>>> More about php exporting csv.
|