•   about 13 years ago

Parsing the CSV

Wow, thought this would be the easy part!

I'm trying to convert the csv into an associative array in PHP and it seems that there is something wrong with this csv because NOTHING reads it, or reads it right.

I picked a few popular csv library on packagist:
/wiakowe/csv-reader
/keboola/csv
/jwage/easy-csv

None of them could parse the file. Keboola made me think that the line breaks are the issue because I got this error message:
"Invalid line break. Please use unix \n or win \r\n line breaks."

Anyone have any luck with this? I suppose my next step will be to try to fix the file, but would have to do that everytime I grab an update..

Sorry for the longish post - this is half a technical question and half an emotional release :p

  • 7 comments

  • Manager   •   about 13 years ago

    Please email me. Sean@uplanme.com

  •   •   about 13 years ago

    Perhaps someone else is having this issue too, care to answer here?

  •   •   about 13 years ago

    I had similar issues but \r\n works for me now. My submission is written in Obj-C though. Here's a snippet of what I'm using. I can see the linebreaks in VIM. Just a note: *nix uses 0xA for a newline character. Windows uses a combination of two characters: 0xA 0xD. 0xD is the carriage return character. Not very familiar with PHP but would it be possible to check for 0xD ?

    Snippet:
    NSString* eventLineItem = [[NSString alloc] initWithData:_downloadData encoding:NSASCIIStringEncoding];
    NSArray *arr = [eventLineItem componentsSeparatedByString:@"\r\n"];

  •   •   about 13 years ago

    This helps - I'll take a look in vim and mess around \r\n

    Thanks!

  • Manager   •   about 13 years ago

    Thanks, Michael, for providing your insight!

  •   •   about 13 years ago

    This has to do with the OS, the file is fine!

  •   •   about 13 years ago

    Yesterday's update to the data file has broken my working parsing. :(

Comments are closed.