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

How to skip header on csv files? #15

Closed
babaganoush opened this issue Jun 30, 2013 · 3 comments
Closed

How to skip header on csv files? #15

babaganoush opened this issue Jun 30, 2013 · 3 comments

Comments

@babaganoush
Copy link

Hello,

I can do something like

if $row[16] == "name"
{
return;
}

however was wondering if there was a way to set a skip option in config so it can skip x number of lines

thanks again for an awesome library

@suin
Copy link
Member

suin commented Jun 30, 2013

Hello, @ipscott

Currently goodby/csv has no configuration to skip a specific line :(
As you know, you can skip if you write custom observer like:

use Goodby\CSV\Import\Standard\Lexer;
use Goodby\CSV\Import\Standard\Interpreter;
use Goodby\CSV\Import\Standard\LexerConfig;

$config = new LexerConfig();
$lexer = new Lexer($config);

$interpreter = new Interpreter();

$lineNumber = 0;

$interpreter->addObserver(function(array $columns) use (&$lineNumber) {
    $lineNumber += 1;

    if ($lineNumber === 1) {
        return;
    }

    // treat $columns here
});

$lexer->parse('some.csv', $interpreter);

@babaganoush
Copy link
Author

ahh haa. That makes sense. Thanks for your quick response.

@emilv
Copy link

emilv commented Sep 1, 2015

For anyone finding this issue through search engines: Since version 1.1.0 (released November 2013) you can skip the first line with $config->setIgnoreHeaderLine(true);

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