我使用下面的csv导出,但我想导出为管道delimeted。
function to_CSV($table) {
$file_csv = "file_csv.csv";
$fp = fopen('php://output', 'w');
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='htmltable' AND TABLE_NAME='$table'";
$result = mysqli_query(db_connect(),$query);
while ($row = mysqli_fetch_row($result)) {
$header[] = $row[0];
}
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$file_csv);
fputcsv($fp, $header);
$query ="SELECT * from $table";
$result = mysqli_query(db_connect(),$query);
while($row = mysqli_fetch_row($result)) {
fputcsv($fp, $row);
}
exit;
}
请帮帮我
答案 0 :(得分:1)
fputcsv接受自定义分隔符作为第三个参数。见http://php.net/manual/en/function.fputcsv.php
例如:
while($row = mysqli_fetch_row($result)) {
fputcsv($fp, $row, '|');
}
答案 1 :(得分:0)