| Recommend this page to a friend! | 
| Info | Documentation | Reputation | Support forum | Blog | Links | 
| Ratings | Unique User Downloads | Download Rankings | ||||
| Not enough user ratings | Total: 210 | All time:  8,376 This week: 60 | ||||
| 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
| File | Role | Description | ||
|---|---|---|---|---|
| Data | Auxiliary data | |||
| Aux. | Configuration script | |||
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Doc. | Auxiliary data | |||
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. | 
| 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.