Below are my code used to generate csv file.
My problem is UTF-8 characters are not coming correctly.
even I tried iconv also, but no result.
PHP CODE
-----------------
$con = mysql_connect('localhost', 'root', ''); $db_selected = mysql_select_db('test', $con); mysql_query("SET NAMES utf8"); $qry_res = mysql_query("SELECT * FROM
table 2
");$filename = "test.csv"; $fp = fopen('php://output', 'w'); //$header = array('id','name'); $header = array("Id","Name"); header('Content-type: application/csv;charset=utf-8'); header('Content-Disposition: attachment; filename='.$filename); fputcsv($fp, $header); while($data = mysql_fetch_row($qry_res)){ fputcsv($fp, $data); } exit;
------------------------------------------
Table value:
-----------------------
Id Name
2 traducción de idiomas
3 תרגום שפות
4 language translation
7 Tłumaczenie na język
Result:
Id Name
2 traducción de idiomas
3 ????? ????
4 language translation
7 T?umaczenie na j?zyk
Thanks in advance.
最佳答案
尝试在标题后添加以下内容:
echo "\xEF\xBB\xBF"; // BOM header UTF-8
关于php - 使用 php 以 UTF-8 格式导出到 CSV for Excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36739350/