Skip to content

Instantly share code, notes, and snippets.

@roneigebert
Last active June 14, 2016 18:33
Show Gist options
  • Save roneigebert/ed58f663e48f084660c13d6b145dbc23 to your computer and use it in GitHub Desktop.
Save roneigebert/ed58f663e48f084660c13d6b145dbc23 to your computer and use it in GitHub Desktop.
Php Csv
<?php
class Csv{
private $output;
private $delimiter;
function __construct($file_name, $delimiter = ';'){
$this->output = fopen('php://output', 'w');
$this->delimiter = $delimiter;
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $file_name);
}
function writeLine($data_array){
fputcsv($this->output, $data_array, $this->delimiter);
}
function browserDownload(){
fclose($this->output);
exit(0);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment