Skip to main content
Inspiring
October 12, 2019
Question

Trying to create CSV for Mac using PHP

  • October 12, 2019
  • 1 reply
  • 353 views

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>';

 

 

 

 

    This topic has been closed for replies.

    1 reply

    revdaveAuthor
    Inspiring
    October 12, 2019

    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 . '";');