Im building a hand made export system for educational purposes in my new website and im having problem with the encoding of the csv in the end. (greek characters)
The code of the script:
if(isset($_POST['export'])){
header("Content-Encoding: UTF-8");
header("Content-type: text/csv; charset=utf8");
header("Content-Disposition: attachment; filename=oramatismos.csv");
$export_query = $connect->prepare("SELECT * FROM oramatismos");
$export_query->execute();
fputcsv($file, explode(',',$titles));
while($list = $export_query->fetch(PDO::FETCH_ASSOC)){
fputcsv($file,$list,';',' ');
}
fclose($file);
exit();
}
The database table columns are set to utf8_unicode_ci
.
The website is build with PDO and in the connection the code is as follows:
try{
$connect = new PDO("mysql:host=".HOST.";dbname=".DB.";charset=utf8",
DB_USER,DB_PASS);
} catch(Exception $e){
echo $e->getMessage();
}