Mini Shell
<?php
class CSV {
public $line;
private $output;
private $eol = "\r\n";
public function __construct($CSVfile, $CSVheader = null) {
$csvHeader = is_null($CSVheader) ? null : implode(";",$CSVheader);
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=' . $CSVfile, true, 200);
$this->output = fopen('php://output','w');
fwrite($this->output, $bom = chr(0xEF) . chr(0xBB) . chr(0xBF) ); // Write BOM character sequence to fix UTF-8 in Excel
if(!is_null($csvHeader)) {
fwrite($this->output, $out = $csvHeader . $this->eol);
}
$this->line = array();
}
public function pushValue($value) {
array_push($this->line,$value);
}
public function writeLine() {
fwrite($this->output, $out = implode(';',$this->line) . $this->eol);
$this->line = array();
}
public function startDownload() {
fclose($this->output);
die();
}
}