Just add a byte order sign with a simple echo just before writing the first line if you want to make any program interpret the file as UTF-8 encoding:
$input_array[] = ['注文日時', '受注番号',]; $input_array[] = ['2015-09-30', 'INV-00001',]; echo "\xEF\xBB\xBF";/// Byte Order Mark HERE!!!! /** open raw memory as file, no need for temp files, be careful not to run out of memory thought */ $f = fopen('php://memory', 'w'); /** loop through array */ foreach ($input_array as $line) { /** default php csv handler **/ fputcsv($f, $line, ','); } /** rewrind the "file" with the csv lines **/ fseek($f, 0); /** modify header to be downloadable csv file **/ header('Content-Encoding: UTF-8'); header('Content-Type: application/csv; charset=UTF-8'); header('Content-Disposition: attachement; filename="my_csv_file.csv";'); /** Send file to browser for download */ fpassthru($f); die();
Alternatively select the Unicode Character set when you import it using Excel or Open Calc, otherwise opening it directly using notepad / textedit / etc, no problem 
source share