Из mysql в excel сохраняет кракозябры
Какие нужно добавить паметры, чтобы кириллицу в файле excel сохраняло?
<?php
include("config.php");
global $connection;
$ts = date('mdY-His');
$sql = "SELECT * FROM price";
$result = mysqli_query($connection, $sql) or die(mysqli_error());
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=importdetails-".$ts.".xls");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Transfer-Encoding: binary ");
// here is the formatting for Excel
$sep = "\t"; //tabbed character
// printing the column names
/* for ($i = 0; $i < mysqli_num_fields($result); $i++) {
echo mysqli_fetch_field($result,$i) . "\t";
}*/
print("\n");
?>
<?php
while($row = mysqli_fetch_row($result))
{
$schema_insert = "";
for($j = 0; $j < mysqli_num_fields($result); $j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
?>
Источник: Stack Overflow на русском