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

BOM and enclosured multiline data #483

Closed
cbepxpa3ym opened this issue Feb 3, 2023 · 2 comments
Closed

BOM and enclosured multiline data #483

cbepxpa3ym opened this issue Feb 3, 2023 · 2 comments
Assignees

Comments

@cbepxpa3ym
Copy link

Bug Report

Information Description
Version 9.8.0
PHP version 8.1
OS Platform Windows 11

Summary

There is an issue with BOM and enclosured multiline data.

Standalone code, or other way to reproduce the problem

Option 1

Create new file in Excel and enter this text into the 1st column:

image

Save it as CSV with UTF8 encoding and run the following code:

var_export(Reader::createFromPath($path)->fetchOne()[0]);

Option 2

Run the following code:

$data = Reader::BOM_UTF8 . <<<CSV
"start
end"
CSV;

var_export(Reader::createFromString($data)->fetchOne()[0]);

Expected result

'start
end'

Actual result

'"start'

Note

It works as expected if there is no BOM.

@nyamsprod
Copy link
Member

@cbepxpa3ym thanks for reporting the bug. This on is due to the underlying PHP CSV parser. Not sure If I can easily fix it. I will have to take a closer look at how to remove the BOM sequence prior to ask PHP to parse the CSV

@nyamsprod
Copy link
Member

Once the next minor version is released you will be able to do the following:

<?php

use League\Csv\Reader;
use League\Csv\SkipBOMSequence;

SkipBOMSequence::register();
$reader = Reader::createFromString($sequence.$data);
$reader->includeInputBOM();
$reader->addStreamFilter(SkipBOMSequence::getFiltername());

Which will fix your issue. If you can't wait until then you can already copy/paste the following class https://github.com/thephpleague/csv/blob/master/src/SkipBOMSequence.php in your codebase. Make sure to read the documentation to understand its usage and shortcomings https://csv.thephpleague.com/9.0/connections/bom/#removing-the-bom-sequence .

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

No branches or pull requests

2 participants