0
Trying to create CSV for Mac using PHP
Contributor
,
/t5/coding-corner-discussions/trying-to-create-csv-for-mac-using-php/td-p/10665864
Oct 12, 2019
Oct 12, 2019
Copy link to clipboard
Copied
Hi all,
I have a data set and want to save as CSV download...
Basically it's working however my mac is not recognizing the /n (new lines)
Did I script this wrong?
Any ideas how to get this working on a mac?
Also when I look at the download file I do not see any line feed or chr(13) return characters....
foreach ($records as $record) {
$alldata .= $record['id'] . "," .$record['Name'] . "," .$record['Info'] . "\n";
}
$response = "data:text/csv;charset=utf-8,id,Name,Info\n";
$response .= $alldata;
echo '<a href="'.$response.'" download="test.csv">download</a>';
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
revdave
AUTHOR
Contributor
,
LATEST
/t5/coding-corner-discussions/trying-to-create-csv-for-mac-using-php/m-p/10665876#M1400
Oct 12, 2019
Oct 12, 2019
Copy link to clipboard
Copied
looks like these headers are getting it working..... so disregard for now
Thanks
$filename = "test1.csv";
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

