PHP导出到csv,编码为excel

时间:2016-03-14 12:20:46

标签: php excel csv character-encoding

我在Windows桌面上的xampp环境中编写了一个简单的php应用程序。它将html表的简单输出转换为csv文件。它工作正常。

现在我将应用程序移动到linux apache服务器。现在CSV导出也可以正常工作但是当我用excel打开它(它在记事本中正确显示)时,不会显示德语变音符号。我怎么说,这在我的xampp服务器上运行良好。你知道我的错误在哪里吗?

Php default_chartype =“utf-8”

<?php

include('func/connect.php');

header("Content-type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=export".time().".csv; charset=utf-8");
header('Content-Transfer-Encoding: binary');
header("Pragma: no-cache");
header("Expires: 0");



$date = explode(" ", $_GET['startDate']);
$monthname= $date[0];
$month=1;
$year= $date[1];
$monthArray = array("January","February","March","April","May","June","July","August","September","October","November","December");

for($i=1;$i<=$monthArray;$i++){
     if($monthArray[$i]==$monthname){
        $month++;
        break;
    }
    else{
        $month++;
    }
}

echo“PNR; Vorname; Nachname; Betrag \ r \ n”;

$q = "SELECT mitarbeiter.ID,mitarbeiter.Vorname,mitarbeiter.Nachname, SUM(Betrag) as Betrag FROM mitarbeiter INNER JOIN transaktionen on mitarbeiter.ID= transaktionen.PNR WHERE obsolete IS NULL AND transaktionen.Date BETWEEN '".$year."-".$month."-01' AND '".$year."-".$month."-".cal_days_in_month(CAL_GREGORIAN, $month, $year)."' GROUP BY ID";
$result = mysqli_query($mysqli, $q) or die ('Unable to execute query. '. mysqli_error($q));

while($query = mysqli_fetch_assoc($result)) {
    echo '="'.$query["ID"].'";'. $query["Vorname"].";". $query["Nachname"].";". number_format($query["Betrag"], 2, ',', '')."\r\n";
}

&GT;

0 个答案:

没有答案