mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Updated README.md to new name & namespace
This commit is contained in:
25
README.md
25
README.md
@@ -1,11 +1,11 @@
|
|||||||
# parseCSV
|
# ParseCsv
|
||||||
|
|
||||||
parseCSV is an easy to use PHP class that reads and writes CSV data properly. It
|
ParseCsv is an easy to use PHP class that reads and writes CSV data properly. It
|
||||||
fully conforms to the specifications outlined on the on the
|
fully conforms to the specifications outlined on the on the
|
||||||
[Wikipedia article][CSV] (and thus RFC 4180). It has many advanced features which help make your
|
[Wikipedia article][CSV] (and thus RFC 4180). It has many advanced features which help make your
|
||||||
life easier when dealing with CSV data.
|
life easier when dealing with CSV data.
|
||||||
|
|
||||||
You may not need a library at all: before using parseCSV, please make sure if PHP's own `str_getcsv()`, ``fgetcvs()`` or `fputcsv()` meets your needs.
|
You may not need a library at all: before using ParseCsv, please make sure if PHP's own `str_getcsv()`, ``fgetcvs()`` or `fputcsv()` meets your needs.
|
||||||
|
|
||||||
This library was originally created in early 2007 by [jimeh](https://github.com/jimeh) due to the lack of built-in
|
This library was originally created in early 2007 by [jimeh](https://github.com/jimeh) due to the lack of built-in
|
||||||
and third-party support for handling CSV data in PHP.
|
and third-party support for handling CSV data in PHP.
|
||||||
@@ -25,8 +25,7 @@ require_once 'parsecsv.lib.php';
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* parseCSV is the only complete and fully featured CSV solution for PHP (as
|
* ParseCsv is a complete and fully featured CSV solution for PHP
|
||||||
far as I know).
|
|
||||||
* Supports enclosed values, enclosed commas, double quotes and new lines.
|
* Supports enclosed values, enclosed commas, double quotes and new lines.
|
||||||
* Automatic delimiter character detection.
|
* Automatic delimiter character detection.
|
||||||
* Sort data by specific fields/columns.
|
* Sort data by specific fields/columns.
|
||||||
@@ -46,14 +45,14 @@ require_once 'parsecsv.lib.php';
|
|||||||
**General**
|
**General**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$csv = new parseCSV('data.csv');
|
$csv = new ParseCsv\Csv('data.csv');
|
||||||
print_r($csv->data);
|
print_r($csv->data);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Tab delimited, and encoding conversion**
|
**Tab delimited, and encoding conversion**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$csv = new parseCSV();
|
$csv = new ParseCsv\Csv();
|
||||||
$csv->encoding('UTF-16', 'UTF-8');
|
$csv->encoding('UTF-16', 'UTF-8');
|
||||||
$csv->delimiter = "\t";
|
$csv->delimiter = "\t";
|
||||||
$csv->parse('data.tsv');
|
$csv->parse('data.tsv');
|
||||||
@@ -63,7 +62,7 @@ print_r($csv->data);
|
|||||||
**Auto-detect delimiter character**
|
**Auto-detect delimiter character**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$csv = new parseCSV();
|
$csv = new ParseCsv\Csv();
|
||||||
$csv->auto('data.csv');
|
$csv->auto('data.csv');
|
||||||
print_r($csv->data);
|
print_r($csv->data);
|
||||||
```
|
```
|
||||||
@@ -71,7 +70,7 @@ print_r($csv->data);
|
|||||||
**Modify data in a CSV file**
|
**Modify data in a CSV file**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$csv = new parseCSV();
|
$csv = new ParseCsv\Csv();
|
||||||
$csv->sort_by = 'id';
|
$csv->sort_by = 'id';
|
||||||
$csv->parse('data.csv');
|
$csv->parse('data.csv');
|
||||||
# "4" is the value of the "id" column of the CSV row
|
# "4" is the value of the "id" column of the CSV row
|
||||||
@@ -82,7 +81,7 @@ $csv->save();
|
|||||||
**Replace field names or set ones if missing**
|
**Replace field names or set ones if missing**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$csv = new parseCSV();
|
$csv = new ParseCsv\Csv();
|
||||||
$csv->fields = ['id', 'name', 'category']
|
$csv->fields = ['id', 'name', 'category']
|
||||||
$csv->parse('data.csv');
|
$csv->parse('data.csv');
|
||||||
```
|
```
|
||||||
@@ -92,7 +91,7 @@ $csv->parse('data.csv');
|
|||||||
_Only recommended when you know the exact structure of the file._
|
_Only recommended when you know the exact structure of the file._
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$csv = new parseCSV();
|
$csv = new ParseCsv\Csv();
|
||||||
$csv->save('data.csv', array(array('1986', 'Home', 'Nowhere', '')), true);
|
$csv->save('data.csv', array(array('1986', 'Home', 'Nowhere', '')), true);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -100,7 +99,7 @@ $csv->save('data.csv', array(array('1986', 'Home', 'Nowhere', '')), true);
|
|||||||
a file and download it**
|
a file and download it**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$csv = new parseCSV();
|
$csv = new ParseCsv\Csv();
|
||||||
$csv->output('movies.csv', $array, array('field 1', 'field 2'), ',');
|
$csv->output('movies.csv', $array, array('field 1', 'field 2'), ',');
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -108,7 +107,7 @@ For more complex examples, see the ``tests`` and `examples` directories.
|
|||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
* parseCSV is based on the concept of [Ming Hong Ng][ming]'s [CsvFileParser][]
|
* ParseCsv is based on the concept of [Ming Hong Ng][ming]'s [CsvFileParser][]
|
||||||
class.
|
class.
|
||||||
|
|
||||||
[ming]: http://minghong.blogspot.com/
|
[ming]: http://minghong.blogspot.com/
|
||||||
|
|||||||
Reference in New Issue
Block a user