-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field containing comma creates an parsing issue while using the save() function #177
Comments
@romainlaisne Thanks for posting your problem here. I believe this is how CSV should work with quotes contained within cells. I just wrote a test to see what would happen and found nothing surprising: public function testSaveWithDelimiterOfComma() {
$this->csv = new Csv();
$this->csv->heading = false;
$this->csv->delimiter = ",";
$this->csv->linefeed = "\n";
$this->csv->data = [
[
'3,21',
'newsletter',
'Monsieur',
'free travel',
],
[
'"9,72"',
'newsletter',
'Madame',
'"free travel"',
],
];
$expected =
'"3,21",newsletter,Monsieur,free travel' . "\n" .
'"""9,72""",newsletter,Madame,"""free travel"""' . "\n";
$actual = $this->csv->unparse();
self::assertSame($expected, $actual);
} Both Excel 2016 and Open Office 4.1.3 opened that correctly. For example: |
Thanks for your reply and setting up a test. An extra info, I use version 1.0 of the library. Perhaps something has been corrected since then? Thanks |
Could you paste your code or source data? This particular behavior was not changed since the 1.0 release. |
Hi, Concerning code, I am using $parseCsvService->save($temp_csv_path, $csv_data, $append, $csv_header); I see you use To test, we can just pass these arrays to the $csv_data=[['3,21']]; and a header : $csv_header=array("header1"); |
@romainlaisne Your last example wrote a file with this content:
I checked with version 1.0.0 and with the current To me, this looks perfect and expected. What did you expect? |
@romainlaisne is your issue solved now? This ticket is pretty damn old and it would be nice to close it with a remark of success. Cheers, |
Hi,
I am parsing a php array to csv using the save() function of this library.
I get an parsing issue, the fields are not parse correctly, when one of the field in my php array contains an comma, which is also the field delimiter in my case.
Here is an example of the CSV output
,"""9","72""",,newsletter,,abos_speedresa,Monsieur,"free travel"
See that the value was 9,72 and it has been strangely quoted!
"free travel" has been correctly parsed with added quote however.
If anyone has an idea how to fix this?
Thanks in advance
The text was updated successfully, but these errors were encountered: