-
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="user.csv"');
- header('Cache-Control: max-age=0');
-
- $sql = 'select * from tbl where ……';
- $stmt = $db->query($sql);
-
- $fp = fopen('php://output', 'a');
-
- $head = array('姓名', '性别', '年龄', 'Email', '电话', '……');
- foreach ($head as $i => $v) {
-
- $head[$i] = iconv('utf-8', 'gbk', $v);
- }
-
- fputcsv($fp, $head);
-
- $cnt = 0;
-
- $limit = 100000;
-
- while ($row = $stmt->fetch(Zend_Db::FETCH_NUM)) {
- $cnt ++;
- if ($limit == $cnt) {
- ob_flush();
- flush();
- $cnt = 0;
- }
- foreach ($row as $i => $v) {
- $row[$i] = iconv('utf-8', 'gbk', $v);
- }
- fputcsv($fp, $row);
- }
qbjHTML5中文学习网 - HTML5先行者学习网qbjHTML5中文学习网 - HTML5先行者学习网