0

我想创建一个 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";
4

1 回答 1

1

不,我从 Mysql qquery 获得的数据是希腊字符

确保您的数据库连接是 UTF-8 编码的。请参阅UTF-8以了解如何做到这一点。

于 2013-04-04T07:59:32.113 回答