你好,我有这段代码可以将我的数据从.xls 导出,但我的编码有问题,这是我的代码
<?php
header("Content-Type: text/plain;charset=UTF-8");
function cleanData(&$str)
{
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
// filename for download
$filename = "website_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
$data = array(
array('firstname' =>'Name', 'last_name' => 'Last Name', 'age' => '25'),
array('firstname' =>'name 2', 'last_name' => 'Last Name 2', 'age' => '27')
);
$flag = false;
foreach($data as $row) {
if(!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\r\n";
}
exit;
?>
我尝试了编码 iso-8859-7、windows-1253 和 UTF-8,我想用希腊字符导出我的所有数据都是 UTF-8。谢谢你的帮助