thephpleague/csv

the Statement limit character for each field?

ducwp opened this issue · 4 comments

ducwp commented

I have a csv file with long text fields and I cant retrieve all text with Statement.

Is is limit?

@ducwp did you try with basic PHP CSV functionnalities ? do you have a reproducible script ? Without any information it is hard to know if it's an issue with the library or with how you are using it 🤔

ducwp commented

@ducwp did you try with basic PHP CSV functionnalities ? do you have a reproducible script ? Without any information it is hard to know if it's an issue with the library or with how you are using it 🤔

I didn't try with basic PHP CSV functionnalities.

this my csv file: https://www.mediafire.com/file/skykw8n7nt0hf1n/tiki-tui-thoi-trang-nam.csv/file

and this is php code:

require_once __DIR__ . '/vendor/autoload.php';

use League\Csv\Reader;
use League\Csv\Statement;

$file_in = 'tiki-tui-thoi-trang-nam.csv';

$csv = Reader::createFromPath($file_in, 'r');
$csv->setHeaderOffset(0); //set the CSV header offset

$stmt = Statement::create()->limit(5);

$records = $stmt->process($csv);

foreach ($records as $i => $record) {
    print_r($record['next_data']);
 }

$record['next_data'] will not return the full text, it has been truncated.

@ducwp I believe the issue is not with the package but with the content of your CSV. From what I understand your CSV document contains json data. You do know that most of the times JSON and CSV share the same delimiter character the " . So depending on how correct the encoding of you CSV was done your result when using the json_decode function does not surprise me. The CSV parser is being mislead by the json content and the parser bail out early.

So nothing the package can do, you need to tell/ask the owner of the CSV to correctly built one when encoding json into a CSV.

Hopes this clarify your issue.

ducwp commented

You're right. I discovered the problem. The problem is the comma "," in the CSV file.
The library is awesome. Thanks for the hard work.