Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
wfpl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
18971ff
)
csv: no trailing \t, no newlines within
author
Jason Woofenden
<jason@jasonwoof.com>
Sun, 5 Feb 2012 00:06:00 +0000
(19:06 -0500)
committer
Jason Woofenden
<jason@jasonwoof.com>
Sun, 5 Feb 2012 00:06:00 +0000
(19:06 -0500)
csv.php
patch
|
blob
|
history
diff --git
a/csv.php
b/csv.php
index
d2d90e3
..
f9e311a
100644
(file)
--- a/
csv.php
+++ b/
csv.php
@@
-4,14
+4,21
@@
# 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
# 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
+# I can't figure out how to get multi-line fields to work, so replace newlines with 4 spaces.
function array2d_to_csv_download($data, $filename) {
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=' . $filename);
foreach($data as $row) {
function array2d_to_csv_download($data, $filename) {
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=' . $filename);
foreach($data as $row) {
+ $first = true;
foreach($row as $el) {
foreach($row as $el) {
- echo '"' . str_replace('"', '""', $el) . "\"\t";
+ if($first) {
+ $first = false;
+ } else {
+ echo "\t";
+ }
+ echo '"' . str_replace("\n", " ", str_replace('"', '""', $el)) . '"';
}
}
- echo "\n"; # apparently can be \n or \r\n
+ echo "\r\n";
}
exit();
}
}
exit();
}