创建XLS文件(希腊字符)

时间:2013-04-04 07:57:30

标签: php

我想用数据库中的一些信息创建一个XLS文件,我想从数据库中检索的数据都是希腊字符。我有这个代码,当我执行代码时,我只得到一些符号。任何人都知道我需要改变什么来正确地获得希腊字符? 编辑:问题是我从Mysql数据库和标题中检索的数据 这是代码

$sql = "SELECT tmima,sex,surname,address,postcode,phone1,phone2 FROM student"; //the query
$result = $db->prepare($sql);
$result->execute();

$column = $result->columnCount();   
$header = "";

$head = array("Τμήμα","Φ","Επίθετο","Όνομα","Μητρώο"); //headings of the XLS

for($i = 0; $i < $column;$i++ ){
    $header .= $head[$i]."\t";
}

$data = "";

while($row = $result->fetch(PDO::FETCH_ASSOC)/*mysql_fetch_row($rec)*/){
    $line = '';
    foreach($row as $value){

        if((!isset($value)) || ($value == " ")){
            $value = "\t";
        }else{
            $value = str_replace( '"' , '""' , $value );
            $value = '"' . $value . '"' . "\t";
        }//end of if-else

        $line .= $value;
    }//end of foreach

    $data .= trim( $line ) . "\n";

}//end of while($row = mysql_fetch_row($rec))


$data = str_replace("\r" , "" , $data);

if ($data == ""){
    $data = "\n No Record Found!\n";                       
}

header('Content-Description: File Transfer');
header('Content-Type: application/ms-excel; charset=utf8');
header("Content-Disposition: attachment; filename=Student_data.xls");
//header("Content-Transfer-Encoding: binary ");
header("Expires: 0");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Pragma: public");

print "$header\n$data";

1 个答案:

答案 0 :(得分:1)

我从Mysql查询得到的数据没有希腊字符

确保您的数据库连接是UTF-8编码的。有关如何执行此操作,请参阅UTF-8 all the way through