我正在使用以下 2 个函数将名为 eco_customers 的表中的数据导出到 excel 文件
但我对阿拉伯字符有疑问,它们显示已损坏,如何修改编码以更正 excel 文件中的阿拉伯字符问题
function cleanData(&$str) {
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"'))
$str = '"' . str_replace('"', '""', $str) . '"';
}
function customer_export(){
$filename = "cutomers_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel, charset=UTF-8; encoding=UTF-8");
$flag = false;
$result = db_query("SELECT name, arabic_name, phones, fax, address, country, city, email, website, registration_no FROM eco_customers ") or die('Query failed!');
while(false !== ($row = db_fetch_array($result))) {
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";
}
}