0
所以我發現一個腳本從數據庫表中獲取一個csv文件。數據庫表到csv字符編碼
<?php
header('Content-Type: text/csv; charset=utf-8 ');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('id','Name', 'Email', 'age','tekens'));
// fetch the data
mysql_connect('localhost', 'name', 'pass');
mysql_select_db('name');
$rows = mysql_query('SELECT * FROM info');
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows))
fputcsv($output, $row);
?>
該代碼的作品,但我有麻煩的人物。我的數據庫表如下所示: Database table
這就是我希望它在我的csv文件中。但是我的csv文件看起來像這樣:Csv file
在csv文件中,Хой顯示爲「???」。有沒有辦法來解決這個問題?
對不起,如果它是重複的。我嘗試了很多不同的東西。
http://stackoverflow.com/questions/279170/utf-8-all-the-way-through/279279 ......我這個問題/答案已經在一個標籤中打開了一年多了,而且我仍然經常將URL複製/粘貼到註釋中* *嘆息* * ... *提示:您沒有在db上設置charset連接器本身* – CD001
http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php ...和* mysql _ \ **庫已棄用。 – CD001
你嘗試設置'mysql_query(「SET character_set_results ='utf8',character_set_client ='utf8',character_set_connection ='utf8',character_set_database ='utf8',character_set_server ='utf8'」,$ conn);'連接好嗎? –