I want to export csv files from php. I decided to use \t = tab as separator to make it unique (use comma as separator is not a good choice because it change from countries to countries). But if i add sep="\t" to my csv it will not recognize the utf-8 bom and when i open the csv in excel, it shows up using ? character to replace °,à, ecc.. If i remove the string "sep=\t" it's decode perfectly in UTF-8 but it won't recognize the \t as separator. How could i use both "sep=\t" and utf-8 bom?
Here is my code:
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="export.csv"');
/*UTF-8 BOM (Byte Order Mark)
\x = caratteri codifica esadecimale */
echo "\xEF\xBB\xBF";
$f = fopen('php://output', 'w');
fwrite($f, "sep=\t");
foreach ($array_to_csv as $line) {
fputcsv($f, $line,"\t");
}