Reputation: 1994
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.
Upvotes: 0
Views: 494
Reputation: 3580
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.
Upvotes: 1