CSV parser with callbacks on fields

Installs: 30

Dependents: 0

Stars: 1

Watchers: 2

Forks: 1

Open Issues: 2

Language: PHP

0.1.1 2014-12-15 17:15 UTC


Official repo stats

Build Status Coverage Status Scrutinizer Quality Score

CSVMapper is a PHP library which parses CSV files.

It allows to map the file to an array by defining some file configurations and each (wanted) columns properties.

File Settings

CSVMapper needs to now where the file is located and which is the columns separator.

It il also possible to specify how many columns are expected so that it aborts if the number of columns doesn't match.

    $setting = new SettingManager();


CSVMapper extracts only the columns which are defined with mappings. With a mapping it is possible to specify the position of the column, which function to apply to the value and how to test the value.

    $mapping = new MappingManager();
    // retrieve column number 1 (counting from 0) and label it as year
    $mapping->set_mapping("year", array('key'=>1,'fn'=>FALSE,'test'=>FALSE));
    // retrieve column number 2 (counting from 0) and label it as temperature, apply to each value the function 'return floatval($input);'
    $mapping->set_mapping("temperature", array('key'=>2, 'fn'=>create_function('$input','return floatval($input);'),'test'=>FALSE));