class_mcCsv.inc.php
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class mcCsv {
/**
* transform array to csv format and export as file
*
* @since 20110920 @author n@mensch.coop
* @static
* @downgraded for php4
*
* @param array $param_array
* @param type $param_filename
* @param array $param_search
* @param array $param_replace
*/
function exportArrayToCsv(array $param_array, $param_charset='utf-8', $param_filename='download.csv', array $param_search = array('"', ';'), array $param_replace = array("'", " ")) {
$ausgabe = '';
if (is_array($param_array) && count($param_array)!=0) {
foreach ($param_array as $daten) {
if (is_array($daten) == true) {
foreach ($daten as $key => $value) {
$ausgabe .= '"'.str_replace($param_search, $param_replace, $daten[$key]).'";';
}
}
$ausgabe .= "\n";
}
} else {
$ausgabe .= '"no data;"';
}
if (headers_sent() == false) {
header("Content-type: text/csv; charset='.$param_charset");
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header("Content-Disposition: attachment; filename =".$param_filename);
header('Pragma: no-cache');
}
echo $ausgabe;
}
}
?>