ballhogjoni Posted March 29, 2014 Share Posted March 29, 2014 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 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 29, 2014 Share Posted March 29, 2014 you didn't show us the actual code. (in tags please) Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 29, 2014 Share Posted March 29, 2014 and a var_dump() of the actual offending data... Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted March 29, 2014 Author Share Posted March 29, 2014 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); Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 29, 2014 Share Posted March 29, 2014 (edited) 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 March 29, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 30, 2014 Share Posted March 30, 2014 So - where is the code that is doing this work for you? Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 2, 2014 Author Share Posted April 2, 2014 Ok so it looks like it was working the whole time. When I preview the csv in open office it shows the correct data, but when I open it the comma's are gone. My guess is it's a bug in open office. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 2, 2014 Share Posted April 2, 2014 it's likely the (number) format that is selected for that excel column is altering the values. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.