Skip to content

Extend PHP's native CSV parsing and API from the SplFileObject class but treat the first row's values as keys on the remaining rows.

License

Notifications You must be signed in to change notification settings

mikefrank-ca/parsecsv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ParseCsv

Extend PHP's native CSV parsing from the SplFileObject class but provide features to use the first row's values as keys on the remaining rows.

There are other libraries which accomplish the similar thing, but they are memory inefficient and rely on their own (sometimes buggy) parsing implementation.

<?php
$oCsv = new ParseCsv('users.csv');
$oCsv->firstRowHeader();

foreach($oCsv as $aRow) {
    print_r($aRow);
}

Given the example users.csv file:

id,firstName
11,Billy

The resulting output will be:

Array
(
    [id] => 11
    [firstName] => Billy
)

Install

$ composer require bluefrg/parsecsv:dev-master

About

Extend PHP's native CSV parsing and API from the SplFileObject class but treat the first row's values as keys on the remaining rows.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages