Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to create CSV for Mac using PHP

Contributor ,
Oct 12, 2019 Oct 12, 2019

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

 

 

 

 

316
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 12, 2019 Oct 12, 2019
LATEST

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 . '";');
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines