-1

When I use this code, the new CVS file get "" by text with blanks:

//array in csv schreiben
$daten = array_filter($daten);
$csv_array[] = $daten;
$fp = fopen("golfDBtest.csv", 'w');

foreach ($csv_array as $fields) {
    fputcsv($fp, $fields);
}
fclose($fp);

The original CSV:

Reit im Winkel,69.8,131,68.4,126,71.6,129,69.5,127,70,7,4,5,4,13,5,3,4,1,4,9,4,17,3,15,3,11,4,10,4,14,4,18,3,4,4,2,4,8,3,16,5,6,3,12,5,00438640798250

The new file:

"Reit im Winkl",69.8,131,68.4,126,71.6,129,69.5,127,70,7,4,5,4,13,5,3,4,1,4,9,4,17,3,15,3,11,4,10,4,14,4,18,3,4,4,2,4,8,3,16,5,6,3,12,5,00438640798250

How can I write a CVS without ""?

Thanks

David Stutz
  • 2,578
  • 1
  • 17
  • 25
wolli911
  • 7
  • 5
  • can you show the array `$daten`? – Sebastian Brosch Apr 24 '16 at 11:36
  • why are you using array_filter with no function to run? – vishwakarma09 Apr 24 '16 at 11:49
  • $daten = array($_POST['Platz'], $_POST['CRgelb'], $_POST['Slgelb'], $_POST['CRblau'], $_POST['Slblau'], $_POST['CRrot'], $_POST['Slrot'], $_POST['CRorange'], $_POST['Slorange'], $_POST['Par'], $_POST['HCP1'], $_POST['Par1'], $_POST['HCP2'], $_POST['Par2'], $_POST['HCP3'], $_POST['Par3'], $_POST['HCP4'], $_POST['Par4'], $_POST['HCP5'], $_POST['Par5'], $_POST['HCP6'], $_POST['Par6'], $_POST['HCP7'], $_POST['Par7'], $_POST['HCP8'], $_POST['Par8'], $_POST['HCP9'], $_POST['Par9'], $_POST['HCP10'], $_POST['Par10'], $_POST['HCP11'], $_POST['Par11'], $_POST['HCP12'], $_POST['Telefon']); – wolli911 Apr 24 '16 at 12:56
  • I use array_filter to clean empty records in the array – wolli911 Apr 24 '16 at 12:58
  • Using enclosing `"` around a value that contains a line break is perfectly valid CSV “syntax” (in quotes, because there isn’t any defined syntax as such), and surely a good idea in terms of compatibility/readability in a variety of systems/programs. So why would you _need_ it without those in the first place? – CBroe Apr 24 '16 at 13:25

1 Answers1

-1

According to the documentation of fputcsv function it has a default enclosure value: ". Setting this so blank should help your cause.

I'd say this should work:

//array in csv schreiben
$daten = array_filter($daten);
$csv_array[] = $daten;
$fp = fopen("golfDBtest.csv", 'w');

foreach ($csv_array as $fields) {
    fputcsv($fp, $fields, ",", "");
}
fclose($fp);
Casper
  • 1,435
  • 10
  • 22
  • Thanks for answering, but this i tested to. With the parameter ",", "" i got a empty file (0 KB). – wolli911 Apr 24 '16 at 12:53
  • no this doesn't help! test your code and you will see the following warning: `Warning: fputcsv(): enclosure must be a character` – Sebastian Brosch Apr 24 '16 at 13:19
  • The lack of source code didn't give me the ability to test it before submitting it. However, you might wanna take a look at [this question](http://stackoverflow.com/questions/11516811/avoid-default-quotes-from-csv-file-when-using-fputcsv). – Casper Apr 24 '16 at 20:52