Jump to content

fputcsv() not storing comma separated string correctly?


ballhogjoni

Recommended Posts

So I am writing an array of data to $output via fputcsv but for some reason fputcsv it's stripping out the comma in this comma separated string "170,171".

 

$output is the file being written to

$data is an array of data

 

The last element in $data is "170,171" when I open the csv file the string looks like "170171". What is weird and I don't understand is that 3 elements before this also has a comma separated string that looks similiar, "1800,1897,1987". Why is fputcsv($output, $data); stripping out the comma out of the last element and not any of the other elements?

 

I realize that fputcsv($output, $headers); is using the comma as the default delimiter. I tried using fputcsv($output, $headers, "\t"); but it still didn't work.

 

Thanks

ok didn't think you'd need more code because i thought it had something to do with fputcsv

 

Here's a sample var_dump of data

array{ ... [28]=> string(9) "1869,1821" [29]=> string(1) "N" [30]=> int(3) [31]=> string(1) "1" [32]=> string(1) "1" [33]=> string(7) "171,172"}

that var dump is printed the line above fputcsv($output, $data);

the posted data works for me. copy/pasted of csv file content produced from the var_dump() values  - "1869,1821",N,3,1,1,"171,172"

 

problem's most likely either in your code, in something that happens to the csv file after you write the data to it, or in how you are viewing the data in the csv file. what's your php code (i suspect you are overwriting the existing output data file, giving a mix of old and new data that happens to end exactly at the point you noticed), what are you using this csv for (are you opening it in excel or other), and how are you viewing it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.