$fp = fopen('file.csv', 'w'); // output BOM fwrite($fp, "\xEF\xBB\xBF"); fputcsv($fp, $data); fclose($fp);