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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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?

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.