Skip to content

Opinionated CSV reader library tuned to the specifics of spreadsheet applications.

Notifications You must be signed in to change notification settings

riiengineering/php-csvreader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-csvreader

This PHP library is an opinionated wrapper around PHP's fgetcsv() function trying to be suitable for guessing (column and row) separators and file encoding as generated by typical spreadsheet applications (looking at you, Excel). The heuristics used to guess the encoding detects Unicode encodings correctly. For legacy code pages, Western European encodings are detected.

Using this library for non-commercial or free software projects is permissible in accordance with the GNU General Public License (version 3 or later).

Installation

Classic

The whole library can be compiled into a single PHP file which can be required from any PHP module:

$ make
$ php <<EOF
<?php
require 'csvreader.php';

// ...
EOF

Composer

In your project's composer.json add the following configuration options and run composer install:

{
	"repositories": [
		{
			"type": "github",
			"url": "https://github.com/riiengineering/php-csvreader"
		}
	],
	"require": {
		"riiengineering/php-csvreader": "dev-main"
	}
}

Usage

<?php
require_once 'csvreader.php'; /* if using the classic method */
require_once 'vendor/autoload.php'; /* if using composer */

$reader = new \riiengineering\csvreader\CSVReader(
	$file,
	array(
		'id',
		'product',
		'currency',
		'price',
	),
	array(
		'separator' => ';',
		'encoding' => 'AUTO',
		'line-separator' => 'AUTO',
	));

foreach ($reader as $row) {
	var_dump($row) . PHP_EOL;
}

riiengineered.

About

Opinionated CSV reader library tuned to the specifics of spreadsheet applications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published