CSV в PHP с запятой без кавычек
Я искал форум и не смог найти похожую ситуацию. У меня есть следующий код для создания файла CSV:
$query2 = "SELECT * FROM mydb where amount='50'";
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_array($result2))
{
$email = $row2['email'];
$amount = $row2['amount'];
$name = $row2['name'];
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// create 2 decimal value on the amount
$mem50 = number_format(floor($amount*100)/100,2, '.', '');
// output the column headings
fputcsv($output, array("$email", "$mem50", "$name", "\r\n"));
}
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($row2)) fputcsv($output, $row);
Проблема в моих следующих результатах:
mytestemail1@gmail.com,50.00,"test name1","
"mytestemail2@gmail.com,50.00,"test name2","
"mytestemail3@gmail.com,50.00,"test name3","
Результат, который я ищу, должен быть:
mytestemail1@gmail.com,50.00,test name1
mytestemail2@gmail.com,50.00,test name2
mytestemail3@gmail.com,50.00,test name3
По какой-то странной причине это добавляет "
а также ,
в конце. Если я использую нормальные значения, то скрипт работает - как aaa, bbb, ccc
1 ответ
Проблема в этой строке:
fputcsv($output, array("$email", "$mem50", "$name", "\r\n"));
Так должно быть:
fputcsv($output, array($email, $mem50, $name));