csv导出代码:
public function export_csv(){
if(($id = $this->get_input('resultId')) == '') {
$this->msg('error');
}
$result = call_mod_func('admin/activity_mod', 'get_result', array($id));
$str = "name,email,mobile,tel" . PHP_EOL;
$str = iconv('utf-8', 'gb2312', $str);
foreach($result['rows'] as $row) {
$name = iconv('utf-8', 'gb2312', $row['name']);
$email = $row['email'];
$mobile = $row['mobile'];
$weixinid = iconv('utf-8', 'gb2312', $row['weixinid']);
$str .= $name . ',' . $email . ',' . $mobile . ',' . $weixinid . PHP_EOL;
}
$filename = date('Ymd', gettime()) . '.csv';
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $str;
}
在Mac系统中,打开时只有一列。
在Windows系统中,打开时有四列。
你能告诉我如何修改代码吗?它可以与多个系统兼容吗?