Skip to content

popy-dev/php-csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is php-csv ?

It is a fully object-oriented CSV reading (soon writing) toolkit, providing various classes to ease CSV file manipulations

Installation

php composer.phar require popy-dev/php-csv:dev-master

Documentation

  1. Basic Usage
  2. Factory

Basic usage

<?php

use Popy\Csv\Reader\SplFileInfoReader;

$file = new SplFileInfo('/path/to/file.csv');
$reader = new SplFileInfoReader($file);

foreach ($reader as $key => $value) {
  // ...
}

Dealing with Microsoft encodings ?

<?php
use Popy\Csv\Reader\CharsetConverterReader;

$rawReader = ...; // Initialize any reader you want (SplFileInfoReader for instance)
$reader = new CharsetConverterReader($rawReader, 'Windows-1252', 'UTF-8');

foreach ($reader as $key => $value) {
  // ...
}

Want named columns ?

Fixed column headers

<?php
use Popy\Csv\Reader\NamedColumnReader;

$rawReader = ...; // Initialize any reader you want (SplFileInfoReader for instance)
$reader = new NamedColumnReader($rawReader, array('col1', 'col2'));

foreach ($reader as $key => $value) {
  // ...
}

Alternative : Use first row as column names

<?php
use Popy\Csv\Reader\AutoNamedColumnReader;

$rawReader = ...; // Initialize any reader you want (SplFileInfoReader for instance)
$reader = new AutoNamedColumnReader($rawReader);

foreach ($reader as $key => $value) {
  // ...
}

About

Php 5.3 CSV reader / writer lib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages