您可以使用fputcsv()以csv格式生成数据
int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )
编辑:
你的代码看起来像这样:
0) { $row = mysqli_fetch_assoc($rs2); $delimiter = ';'; $data = []; foreach ($row as $name => $value){ $data[] = $name; } fputcsv($fp, $data, $delimiter); mysqli_data_seek($rs2,0); while ($row = mysqli_fetch_assoc($rs2)){ fputcsv($fp, $row, $delimiter); } fclose($fp); header('Content-Type: text/csv'); header("Content-Disposition: attachment; filename=$date.csv"); header('Pragma: no-cache'); echo $seperator; } else { fclose($fp); header('Content-Type: text/csv'); header("Content-Disposition: attachment; filename=$date.csv"); header('Pragma: no-cache'); echo "No record modified today"; }