2017 © Pedro Peláez
 

library csvtools

Tools for importing, parsing and structuring CSV files and data

image

almaudoh/csvtools

Tools for importing, parsing and structuring CSV files and data

  • Friday, September 15, 2017
  • by almaudoh
  • Repository
  • 0 Watchers
  • 0 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 9 % Grown

The README.md

CSV Tools

Simple PHP based classes for importing, parsing and structuring CSV files and data., (*1)

It is made up of just two files, which contain a parser and then a mapper. The parser class parses the CSV files, which the mapper class allows mapping of the CSV file headers to another set of keys. The mapper class provides allows iteration over the CSV data and array access to each of the columns. The mapper implements \Iterator, \ArrayAccess and \Countable., (*2)

Example usages:, (*3)

filename.csv

NAME,MOBILE,MOBILE2,EMAIL,CITY,COUNTRY,BIRTH_DAY,WORK,NOTES,ACTIVE_ROLES,WANTED_ROLES
Jolly,2348030783839,,noreply@example.com,NoCity,NoCountry,38758,My work,My Notes,,
Nolly,2348038983839,2348030783839,noreply@example.com,NoCity,NoCountry,38758,My work,My Notes,,
,,,,,,,,,,
Polly,2348030783839,2348030783839,noreply@example.com,NoCity,NoCountry,38758,My work,My Notes,,
Solly,2348030783457,2348030783839,3reply@example.com,NoCity,NoCountry,38758,My work,My Notes,,
,,,,,,,,,,
,,,,,,,,,,
Lolly,2347090783839,,noreply@example.com,NoCity,NoCountry,38758,My work,My Notes,,
Wolly,2347090783234,,1reply@example.com,NoCity,NoCountry,38758,My work,My Notes,,
,,,,,,,,,,
$mapping = [
    'name' => 'NAME',
    'phone' => 'MOBILE',
    'phone2' => 'MOBILE2',
    'email' => 'EMAIL',
    'city' => 'CITY',
    'country' => 'COUNTRY',
    'dob' => 'BIRTH_DAY',
    'address' => 'WORK',
    'notes' => 'NOTES',
    'roles' => 'ACTIVE_ROLES',
    'additional_roles' => 'WANTED_ROLES',
];
$csv = (new CsvDataListMapper())
            ->setSourceFile('filename.csv')
            ->setDataMap($mapping);
foreach ($csv as $record) {
    write_to_database($record);
    print($record['name']);
}

prints, (*4)

Jolly
Nolly

Polly
Solly


Lolly
Wolly

The Versions

15/09 2017

0.9.x-dev

0.9.9999999.9999999-dev

Tools for importing, parsing and structuring CSV files and data

  Sources   Download

GPL-3.0

The Requires

  • php ^5.5.9 || ^7.0

 

The Development Requires

by Aniebiet Udoh

15/09 2017

dev-master

9999999-dev

Tools for importing, parsing and structuring CSV files and data

  Sources   Download

GPL-3.0

The Requires

  • php ^5.5.9 || ^7.0

 

The Development Requires

by Aniebiet Udoh