parsecsv / parsecsv-for-php

CSV data parser for PHP.
MIT License
678 stars 176 forks source link

Replace field names or set ones if missing #172

Closed osc2nuke closed 5 years ago

osc2nuke commented 5 years ago

I first want to explain what i attempt to do, so you understand the situation. I am working on a so called "feed Manager". Some of the feeds (csv's) do not contain headings.

What i try to do is: Count the columns and assign a custom heading to the column i want the data from.

Not tested but:

$csv = new ParseCsv\Csv();
$csv->fields = ['id', 'name', 'category']
$csv->parse('data.csv');

can it also be:

$csv->fields[3] = 'my custom heading';

cause i not quite understand:

Replace field names or set ones if missing

susgo commented 5 years ago

No sorry, this will not work at the moment

osc2nuke commented 5 years ago

Ok, thanks. I solved it using just the default code. One problem left is, as i use "custom headings" (means my csv has NO headings), the csv is parsed skipping the first row. $csv->offset = 0 Not work in this case. Is there any solution for that? Or do i miss a setting?

osc2nuke commented 5 years ago

I will close this and make a new request.