iRail / The-DataTank

DEPRECATED - new repo at http://github.com/tdt/core
http://thedatatank.com
26 stars 9 forks source link

CSV field enclosure #123

Open dtrdewaele opened 12 years ago

dtrdewaele commented 12 years ago

To create a package with a CSV file you have the delimiter parameter, but you don't have a field enclosure. We have a lot of CSV files like this

field1;field2;"item1,item2,item3";field3...

We get error with this files because the delimiter is set to ; and so the item1,item2 will be split also. This results in an error message that we have to much data columns than header columns...

Regards

dtrdewaele commented 12 years ago

Hmm sorry... TDT does something with enclosers, but it doesn't work :) I'll see what I can do

coreation commented 12 years ago

Ah I see, think I know where the problem is, we used to ignore the enclosure problem because we used a function which by default took a " as an enclosure character. However, we changed the read function a little bit, could be that this function was replaced. Maybe add a " to the read function on line 97 in CSV, fgetcsv has an optional parameter for enclosures. Note that we didnt have an enclosure parameter because according to the CSV "standard" (Yes, I know there really isnt one ) there was only one enclosure character ", which was thus by default included in our php getCSV function. I'll try out as well tomorrow!

coreation commented 12 years ago

http://www.php.net/manual/en/function.str-getcsv.php http://www.php.net/manual/en/function.fgetcsv.php

coreation commented 12 years ago

Hmm, if I use this tiny CSV file for a test:

"Postnr","Lokaliteit,endinges","Zonenr","Zonenaam" "1000","BRUSSEL 1","10","Brussels Hoofdstedelijk Gewest" "1020","BRUSSEL 2","10","Brussels Hoofdstedelijk Gewest,,"

Which has several delimiters in enclosures ( double quotes, see RFC for CSV http://www.ietf.org/rfc/rfc4180.txt ), and works fine here. Any updates from your side ?