0

I have a delimited string coming from a service, I want to convert this delimited string with headers to a downlodable CSV file.

    empId,empName,salary,depName,depId
    1,John,20000,IT,2

Could someone help me with a code snippet/reference.

user804401
  • 1,990
  • 9
  • 38
  • 71
  • Isn't this a CSV already? Do you just want to [force a download](http://stackoverflow.com/questions/7263923/how-to-force-file-download-with-php)? – Dave Chen Jul 13 '15 at 05:18

1 Answers1

1

change header first

<?php
    header('Content-Disposition: attachment; filename="downloaded.csv"');
    echo 'empId,empName,salary,depName,depId';
    echo '1,John,20000,IT,2';   
?>

and then echo your output.

Raghavendra
  • 3,530
  • 1
  • 17
  • 18