I\'m writing a CSV file in PHP using fputcsv($file, $data)
.
It all works, however I can\'t just open it in Excel but have to import it and specify the encoding
Despite the "C=comma" in CVS, Excel uses your locale native separator. So supposing fputcsv
always uses a comma, it won't work, if your locale separator is for example a semicolon.
What Google AdSense does, when you click "Export to Excel CSV", is that it uses Tab as a separator. And that works.
To replicate that, set the third parameter (delimiter
) of fputcsv
to override the default comma. E.g. for Tab use: fputcsv($handle, $fields, "\t");
Compare the format of the CSV that works for you against the one generated by fputcsv
.
Consider including example of both in your question. You might get better answers.