Home > php教程 > php手册 > php 生成CSV文件

php 生成CSV文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 09:54:18
Original
951 people have browsed it
<?Php

/**
 * 生成默认以逗号分隔的CSV文件
 * 解决:内容中包含逗号(,)、双引号("")
 * @author zf
 * @version 2012-11-14
 */
header("Content-Type: application/vnd.ms-excel; charset=GB2312");
header("Content-Disposition: attachment;filename=CSV数据.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 after login

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template