I got a coma separated string. I need to convert this to an array and be able to save it as a csv file.
$fp = fopen("abc.csv", "w");
$str = "FRUIT, STOCKS, TYPE\n lychee, instocks, B-type\n strawberry, N/A,A-type\n";
$data = str_getcsv($str);
fputcsv($fp, $data);
fclose($fp);
Currently it outputs the entire string as a single line.
Expected csv output:
FRUIT, STOCKS, TYPE
lychee, instocks, B-type
strawberry, N/A, A-type
<br>or<p>tags to output (line breaks) on screen.abc.csv. When I open the csv file, the entire string as a single line. I want the CSV to be as in my expected out put.\n's will automatically create new lines for it. You just need to later call up that file to view it, rather than write to it.