JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
add csv.php (makes excell CSVs)
authorJason Woofenden <jason@jasonwoof.com>
Wed, 25 Jan 2012 02:22:51 +0000 (21:22 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Wed, 25 Jan 2012 02:22:51 +0000 (21:22 -0500)
csv.php [new file with mode: 0644]

diff --git a/csv.php b/csv.php
new file mode 100644 (file)
index 0000000..d2d90e3
--- /dev/null
+++ b/csv.php
@@ -0,0 +1,17 @@
+<?php
+
+# This file generates what Excell refers to as "CSV" files. This format makes
+# little sense, and does not actually have anything to do with commas.
+
+# pass in a 2d array (array of rows) and it'll send it to the browser
+function array2d_to_csv_download($data, $filename) {
+       header('Content-type: application/csv'); 
+       header('Content-Disposition: attachment; filename=' . $filename); 
+       foreach($data as $row) {
+               foreach($row as $el) {
+                       echo '"' . str_replace('"', '""', $el) . "\"\t";
+               }
+               echo "\n"; # apparently can be \n or \r\n
+       }
+       exit();
+}