Skip to content
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

Enclosure not works properly #519

Closed
JiRysavy opened this issue Feb 1, 2024 · 2 comments
Closed

Enclosure not works properly #519

JiRysavy opened this issue Feb 1, 2024 · 2 comments

Comments

@JiRysavy
Copy link

JiRysavy commented Feb 1, 2024

Bug Report

Enclosure around words is not removed

| 9.14 | |
| 8.1 | |
| Docker on Ubuntu 22.04|

I have some trouble with reading cells data surrounded with ".

I have CSV that looks something like:
"h1";"h2";"h3";"h4";"h5";
"d1";"d2";"d3";"d4";"d5";
"l1";"l2";"l3";"l4";"l5";

and code:
$csv = Reader::createFromPath($filePath, 'rb'); $csv->setHeaderOffset(0) ->setDelimiter(';') ->setEnclosure('"');

I expect, the getResults return to be:
[
[
'h1' => 'd1',
'h2' => 'd2',
'h3' => 'd3',
'h4' => 'd4',
'h5' => 'd5',
],
[
'h1' => 'l1',
'h2' => 'l2',
'h3' => 'l3',
'h4' => 'l4',
'h5' => 'l5',
]
], but actual result is:

[
[
'"h1"' => '"d1"',
'"h2"' => '"d2"',
'"h3"' => '"d3"',
'"h4"' => '"d4"',
'"h5"' => '"d5"',
],
[
'"h1"' => '"l1"',
'"h2"' => '"l2"',
'"h3"' => '"l3"',
'"h4"' => '"l4"',
'"h5"' => '"l5"',
]
],

@codespearhead
Copy link

codespearhead commented Feb 15, 2024

It's actually a feature.

Single quotes are not formally specified in RFC 4180 for enclosing fields, hence their behavior can be inconsistent between different parsers.

@nyamsprod
Copy link
Member

@JiRysavy this is an expected behaviour in how arrays are being presented in PHP. The enclosure you see are part of array representation but not par of your CSV document.

@codespearhead the behaviour has nothing to do with RFC4180.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants