I got a string with semi clones. I want to create a csv file.
$fp = fopen("abc.csv", "w");
$str = "FRUIT; STOCKS; TYPE\n lychee; B-type,A-type; instocks\n strawberry; A-type;N/A\n";
$rows = str_getcsv($str, PHP_EOL);
foreach($rows as $row) {
$data = str_getcsv($row);
fputcsv($fp, explode(';',$data), ";");
}
The fputcsv() doesn't seem to work correctly.
When I open the csv using EXCEL the data should be in separate columns where the semi colon (;) was.
FRUIT TYPE STOCKS
Lychee B-type,A-type instocks
Strawberry A-type N/A
EDIT:
My current output and problems are
1. If there's are more than one words those are wrapped by a " (e.g. below)
FRUIT;STOCKS;TYPE;"COST PER ITEM"
The final output is as (when opened in excel).
FRUIT;STOCKS;TYPE;"COST PER ITEM" Lychee "B-type A-type"; instocks; $54; Strawberry; A-type; N/A; $31;
Each ; is in a seperate column. I want the final output to be like this
FRUIT TYPE STOCKS COST PER ITEM
Lychee B-type,A-type instocks $54
Strawberry A-type N/A $31