/simplecsv

A simple and flexible library for reading and manipulating CSV files in php 5.3

Primary LanguagePHPMIT LicenseMIT

SimpleCsv

SimpleCsv is a simple and flexible library for reading and manipulating CSV files.

Usage

Read CSV from File

$csv = \Reader::create_from_file('./dat.csv');

Read CSV from String

$str = 'header 1, header 2
data 1, data 2';
$csv = \Reader::create_from_string($str);

CSV to Array

// associative array using first line as headers
$csv = \Reader::create_from_file('./dat.csv')
				->to_assoc();

// indexed array w/ no headers
$csv = \Reader::create_from_file('./dat.csv')
				->to_array();

Detect Delimiter

// automatically detect and set the file delimiter type
$csv = \Reader::create_from_file('./dat.csv')
				->detect_delimiter(array('|', '%', '$'))
				->to_assoc();

Installation

Install the SimpleCsv package with Composer.

{
    "require": {
        "AlexBrandes/SimpleCsv": "*"
    }
}

Read more about Composer

System Requirements

PHP >= 5.3.0

TODO

  • Write to Csv
  • Tests

Credits