I made a CSV as an example:
Type, जिल्ला शिक्षा कार्यालय डडेलधुरा,NGOI,NGO Request,21,0,0 Response, 4,0,0
and it has utf-8 characters and i want to export it to excel so i posted it and to export it to excel and after referring to several questions on stackoverflow i did as follow:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Type: text/csv; charset=utf-8");
header('Content-Disposition: attachment; filename=file.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
print $_POST['csv_data'];exit;
the csv is exported to excel nicely but character encoding in not converted and shows something like this: जिलà¥à¤²à¤¾ शिकà¥à¤·à¤¾ कारà¥à¤¯à¤¾à¤²à¤¯ डडेलधà¥à¤°à¤¾ and when i add
echo "\xEF\xBB\xBF";
the character encoding is converted but the data appears in one column like this:
Type, जिल्ला शिक्षा कार्यालय डडेलधुरा,NGOI,NGO
Request,21,0,0
Response, 4,0,0
utf8_encode()to the$_POST['csv_data']à ¤œà ¤¿à ¤²à ¥Âà ¤²à ¤¾ à ¤¶à ¤¿à ¤•à ¥Âà ¤·à ¤¾ à ¤•à ¤¾à ¤°à ¥Âà ¤¯à ¤¾à ¤²à ¤¯ à ¤¡à ¤¡à ¥‡à ¤²à ¤§à ¥Âà ¤°à ¤¾