2017 © Pedro Peláez
 

library csv

Contains the XP Framework's CSV API

image

xp-framework/csv

Contains the XP Framework's CSV API

  • Monday, April 2, 2018
  • by thekid
  • Repository
  • 2 Watchers
  • 0 Stars
  • 30,830 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 7 % Grown

The README.md

CSV File handling for the XP Framework

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version, (*1)

Contains the XP Framework's CSV API, (*2)

Reading

CSV data can be read off any input stream, reader or channel:, (*3)

use util\cmd\Console;
use text\csv\CsvListReader;
use io\streams\FileInputStream;

$csv= new CsvListReader(new FileInputStream('in.csv'));
Console::writeLine($csv->getHeaders());

while ($record= $csv->read()) {
  Console::writeLine('- ', $record);
}

$csv->close();

Writing

CSV data can be written to any output stream, writer or channel:, (*4)

use util\cmd\Console;
use text\csv\CsvListWriter;
use io\streams\FileOutputStream;

$csv= new CsvListWriter(new FileOutputStream('out.csv'));

$csv->setHeader(['name', 'city', 'zip']);
$csv->write(['Timm', 'Karlsruhe', 76137]);
$csv->write(['Alex', 'Karlsruhe', 76131]);

$csv->close();

Character set conversion

Character set decoding is accomplished by passing a TextReader or TextWriter instance with a given character set:, (*5)

use text\csv\{CsvListReader, CsvListWriter};
use io\streams\{FileInputStream, FileOutputStream, TextReader, TextWriter};

// Read from in.csv, which is in cp1252
$in= new CsvListReader(new TextReader(new FileInputStream('in.csv'), 'cp1252'));

// Write to out.csv, converting everything to cp1252
$out= new CsvListWriter(new TextWriter(new FileOutputStream('out.csv'), 'cp1252'));

Format

CSV files usually use the semi-colon to separate values. Depending on the file we're parsing, this might be a different character. Both readers and writers accept an optional second parameter with which the format can be changed., (*6)

use text\csv\{CsvFormat, CsvListReader, CsvListWriter};

$format= (new CsvFormat())->withDelimiter(',');
$format= CsvFormat::$COMMAS;    // Short-hand for the above

$writer= new CsvListWriter(..., $format);
$reader= new CsvListReader(..., $format);

The Versions

02/04 2018

dev-master

9999999-dev http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

02/04 2018

v8.0.1

8.0.1.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/06 2017

v8.0.0

8.0.0.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

29/08 2016

v7.1.0

7.1.0.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

22/02 2016

v7.0.0

7.0.0.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

14/12 2015

v6.2.0

6.2.0.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

30/06 2015

v6.1.1

6.1.1.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

24/05 2015

v6.1.0

6.1.0.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

12/02 2015

v6.0.1

6.0.1.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

10/01 2015

v6.0.0

6.0.0.0 http://xp-framework.net/

Contains the XP Framework's CSV API

  Sources   Download

BSD-3-Clause

The Requires

 

module xp