CSV文件中的空格

时间:2014-04-19 09:23:10

标签: php

我使用php从Database.Iy导出数据问题is.Data导出成功,但它在开始时创建了两个空行。我想删除它们。这是我的代码

if($_POST){
$output = "";
$table = "schedule"; // Enter Your Table Name 
$sql = mysql_query("select * from $table WHERE post_id='".$_POST['schedule_id']."'");
$columns_total = mysql_num_fields($sql);
for ($i = 0; $i < $columns_total; $i++) {
$heading = mysql_field_name($sql, $i);
$output .= '"'.$heading.'",';
}
$output .="\n";
while ($row = mysql_fetch_array($sql)) {
for ($i = 0; $i < $columns_total; $i++) {
$output .='"'.trim($row["$i"]).'",';
}
$output .="\n";
}
$filename = "schedule.csv";
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
echo $output;
exit;
}

1 个答案:

答案 0 :(得分:1)

你应该用带双引号或任何其他字符的空格包装字符串。

请参阅此回答https://stackoverflow.com/a/3933816/1163444

提供的功能
相关问题