I want to export my mysql data to an excel file, I have done it but if I have Greek words they appear with nonsense characters. So I believe I have to add some encoding headers but I didn't found something.
Here is my code:
<?php
//export.php
$pdo = Database::connect();
$output = '';
$query = "SELECT * FROM clients";
$stmt = $pdo->prepare($query);
//Execute the statement.
$stmt->execute();
$clients= $stmt->fetchAll();
$output .= '
<table class="table" bordered="1">
<tr>
<th>Ονοματεπώνυμο</th>
<th>Σταθερό Τηλέφωνο</th>
<th>Email</th>
<th>Διεύθυνση</th>
</tr>
';
foreach($clients as $items):
$output .= "
<tr>
<td>".$items['fullname']."</td>
<td>".$items['phone1']."</td>
<td>".$items['email']."</td>
<td>".$items['address']."</td>
</tr>
";
endforeach;
$output .= '</table>';
header('Content-Type: application/xls');
header('Default-Charset : utf-8 ');
header('Content-Disposition: attachment; filename=download.xls');
echo $output;
?>
I don't mind to change the whole code if you got something better to show me. Thanks in advance