data = preg_replace("/(?data); $consumed += $bucket->datalen; stream_bucket_append($out, $bucket); } return PSFS_PASS_ON; } } /** * WExport helps to export data. * * @package System\WCore * @author Johan Dufau * @author Thibault Vlacich * @version 0.5.0-dev-02-01-2015 */ class WExport { /* $data = array( // Table array( // Row "Column1" => "Row1Value1", // Col "Column2" => "Row1Value3", "Column3" => "Row1Value2" ), array( // Row "Column1" => "Row1Value1", // Col "Column2" => "Row1Value3", "Column3" => "Row1Value2" ) ); */ public static function toCSVNamed($filename_prefix, array &$data) { $filename = $filename_prefix.'_' . date('Ymd-His') . '.csv'; // Disable caching $now = gmdate('D, d M Y H:i:s'); header('Expires: Tue, 03 Jul 2001 06:00:00 GMT'); header('Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate'); header('Last-Modified: '.$now.' GMT'); // Disposition / encoding on response body header('Content-Disposition: attachment;filename='.$filename); header('Content-Transfer-Encoding: binary'); header('Content-Encoding: UTF-8'); header('Content-type: text/csv; charset=UTF-8'); // CRLF filter registration stream_filter_register('crlf', 'crlf_filter'); $output = fopen('php://output', 'w'); // CRLF enabled stream_filter_append($output, 'crlf'); if (!empty($data)) { fwrite($output, "\xEF\xBB\xBF"); // UTF-8 BOM // Columns name fputcsv($output, array_keys(reset($data)), ';'); // Values foreach ($data as $line) { fputcsv($output, $line, ';'); } } fclose($output); exit(); } } ?>