SimpleCsv is a simple and flexible library for reading and manipulating CSV files.
$csv = \Reader::create_from_file('./dat.csv');
$str = 'header 1, header 2
data 1, data 2';
$csv = \Reader::create_from_string($str);
// 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();
// automatically detect and set the file delimiter type
$csv = \Reader::create_from_file('./dat.csv')
->detect_delimiter(array('|', '%', '$'))
->to_assoc();
Install the SimpleCsv
package with Composer.
{
"require": {
"AlexBrandes/SimpleCsv": "*"
}
}
Read more about Composer
PHP >= 5.3.0
- Write to Csv
- Tests
- Written and maintained by Alex Brandes