$csv_file = 'filename.csv';
error_reporting(0);
ini_set('display_errors', 0);
header("Content-type: application/csv");
header('Content-Disposition: attachment; filename = "'.$csv_file.'"');
header('Pragma: no-cache');
header("Expires: 0");
echo $csv = csvFormat::arr_to_csv($data);
exit;
class csvFormat {
static public function arr_to_csv_line($arr) {
$line = array();
foreach ($arr as $v) {
$line[] = is_array($v) ? self::arr_to_csv_line($v) : '"' . str_replace('"', '""', $v) . '"';
}
return implode(",", $line);
}
static public function arr_to_csv($arr) {
$lines = array();
foreach ($arr as $v) {
$lines[] = self::arr_to_csv_line($v);
}
return implode("\n", $lines);
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.