Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (7) | Download .zip | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 207 This week: 1 | All time: 8,399 This week: 560 |
Version | License | PHP version | Categories | |||
csv-to-arrays 2.0.1 | MIT/X Consortium ... | 5.3.0 | PHP 5, Files and Folders, Parsers |
Description | Author | ||||||||||||||||||||||
This class can parse CSV data to indexed or associative arrays. |
|
PHP client to parse CSV data from a file, stream or string into indexed or associative arrays.
Install using composer
#composer.json
{
"require": {
"jabranr/csv-parser": ">=1.0.0"
}
}
Run following to install
$ comsposer install
Initiate a new instance
$csv = new CSV_Parser();
Get data from a string
/@param: string $str/
$csv->fromString( $str );
Get data from a stream
/@param: stream $stream (e.g. php://input)/
$csv->fromStream( $stream );
Get data from a file
/@param: file $file/
$csv->fromFile( $file );
Parse data for output
/
* Set $headers true/false to include top/first row
* and output an associative array
*
* @param: boolean $headers (Default: true)
* @return: array
*/
$csv->parse( $headers );
Example input string
$str = 'id,first_name,last_name;1,Jabran,Rafique';
$csv->fromString( $str );
// Output with headers:
$csv->parse();
Array(
[id] => 1,
[first_name] => 'Jabran',
[last_name] => 'Rafique'
)
// Output without headers:
$csv->parse( false );
Array(
[0] => array(
[0] => 'id',
[1] => 'first_name',
[2] => 'last_name'
),
[1] => array(
[0] => 1,
[1] => 'Jabran',
[2] => 'Rafique'
)
)
© 2015 MIT License - Jabran Rafique
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 file) | ||||
test (1 file) | ||||
.travis.yml | Data | Auxiliary data | ||
autoload.php | Aux. | Configuration script | ||
composer.json | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Auxiliary data |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.