I am trying to show a MySQL row from the database which contains German characters but it shows me the output like below in the CSV file all the English characters works fine I don't know where I am going wrong. Any help will be appreciated.
Output: Ö/öÖ/öÖ/ö Ö/öÖ/öÖ/öÖ/ö Ö/öÖ/ö Ö/öÖ/öÖ/ö Ö/öÖ/öÖ/ö Ö/öÖ/Ã
Input: Ö/öÖ/öÖ/ö Ö/öÖ/ö Ö/öÖ/öÖ/ö Ö/öÖ/öÖ/öÖ/ö Ö/öÖ/öÖ/ö Ö/öÖ/ö
$sql = "SELECT forename,surname,company,address,phone,email FROM `user_data`";
$result = mysqli_query($con,$sql);
$fp = fopen('php://output','w');
$fields=array("forename","surname","company","address","phone","email");
fputcsv($fp, $fields);
while ($list = mysqli_fetch_assoc($result)) {
fputcsv($fp, $list);
}
header('Content-Type: text/plain; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
First you have to make sure that the encoding of your database column/table has the correct charset: SHOW CREATE TABLE Tablename;
Second: When you're inserting data into the table you have to make sure that the encoding you're using is utf8 also.