2017 © Pedro Peláez
 

library csv-tools

image

redcatphp/csv-tools

  • Tuesday, February 28, 2017
  • by surikat
  • Repository
  • 1 Watchers
  • 1 Stars
  • 97 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

No longer actively maintained. I work now with NodeJS and I recommand you to take a look at PapaParse, (*1)

CSV Tools

taken from DelimiterFinder https://github.com/darraghenright/DelimiterFinder

with composer, namespace and autoload support, (*2)

A little utility class that reads a .csv or .dat (or whatever) file and tries to guess the delimiter, (*3)

Usage

Create an instance

Include the file and create a new instance in the usual way; the constructor takes a filepath as a required argument:, (*4)

require_once dirname(__FILE__) . '/DelimiterFinder.php';

try {
    $finder = new DelimiterFinder('path/to/data.csv');
} catch (InvalidArgumentException $e) {
    // file does not exist :o 
} catch (RuntimeException $e) {
    // file is not readable :(
}

The object will try to open a file handle on the filepath provided. If the file is unreadable or non-existent exceptions will be thrown., (*5)

Find

Assuming all went smoothly to this point, it's time to try to guess the delimiter., (*6)

The class searches for a likely delimiter from the following list of usual suspects:, (*7)

  • comma (,), tab (\t) or semicolon (;)

Just call the find method:, (*8)

$delimiter = $finder->find();

If successful, find() stores and returns the matched delimiter. Subsequent calls to do not search the document again; they just return the stored match., (*9)

If at first you don't succeed...

If a match is not successful, the find() method returns false. Subsequent calls to find() will search the document again. You can add any number of custom delimiters to search, which makes repeat searches a little more useful ;), (*10)

$finder->addDelimiter('|');
$delimiter = $finder->find(); // pipe-delimited file? success!

The Versions

28/02 2017

dev-master

9999999-dev

  Sources   Download

MIT

by jo

28/02 2017

v1.0.1

1.0.1.0

  Sources   Download

MIT

by jo

27/02 2017

v1.0.0

1.0.0.0

  Sources   Download

MIT

by jo