mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0486a4bf3e | ||
|
|
90042a553c | ||
|
|
73d7acb493 | ||
|
|
7b6692d7fd | ||
|
|
01d25e0fdd | ||
|
|
c64a4bffd7 | ||
|
|
2d7f18ebc9 | ||
|
|
ee5b34e1c1 | ||
|
|
44929708ca | ||
| c55ab2ec2c | |||
|
|
6784c614ea | ||
|
|
5a70a7bffa | ||
|
|
c1a6946815 | ||
|
|
dbf415bd92 | ||
|
|
c915579955 | ||
|
|
55aaa1eb17 | ||
|
|
ab069e5d2d | ||
|
|
7e7aeba761 | ||
|
|
a3e3582222 | ||
|
|
fff3e73f08 | ||
| f59af53183 | |||
| 629b0c9fd5 | |||
| 698a570a11 | |||
| 2aca09e05d | |||
| 7a9fc101f8 | |||
| a1564a9a99 | |||
| 4b280885f4 | |||
|
|
88ad81f061 | ||
|
|
7e46cc193a | ||
|
|
a274874084 | ||
|
|
dea1b453eb | ||
|
|
9a8bd77eb8 | ||
|
|
89a2817765 | ||
|
|
75d7d51a9c | ||
|
|
9b6dbd9849 | ||
|
|
61d1c27eac | ||
|
|
ecbb0736f1 | ||
|
|
2ab7625bb5 | ||
|
|
0f39cfa75a | ||
|
|
0457fbfba2 | ||
|
|
af5d7cf70d | ||
|
|
531cc66a5e | ||
|
|
178699580e | ||
|
|
8c300568bb | ||
|
|
28967dea20 | ||
|
|
46b42776e4 | ||
|
|
8ba88c582d | ||
|
|
ba1d462044 | ||
|
|
0323d5108b | ||
|
|
2988278f0b | ||
|
|
9301b016c8 | ||
|
|
75038f9d2f | ||
|
|
b72385395e | ||
|
|
eb3c9faa4a | ||
|
|
2f142e7313 | ||
|
|
05dbcaf652 | ||
|
|
4639fa1701 | ||
|
|
8bb8e2d7cf | ||
|
|
c7e1f825a0 | ||
|
|
0638049fb2 | ||
|
|
585a0d472e | ||
|
|
d6a070ce08 | ||
|
|
4454196b4c | ||
|
|
6a6754ca04 | ||
|
|
8dd2e52073 | ||
|
|
e16d818d07 | ||
|
|
9e6fdbb42a | ||
| 85ca7af160 | |||
| 1b91591d32 | |||
|
|
dfe298f4d0 | ||
|
|
fc22bee7ca | ||
|
|
9b64cb07c4 | ||
|
|
2bfa3de220 | ||
|
|
c522cd87a7 | ||
|
|
0395362d66 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
vendor/
|
||||||
|
composer.lock
|
||||||
@@ -1,3 +1,44 @@
|
|||||||
|
parseCSV 0.4.3 beta
|
||||||
|
-----------------------------------
|
||||||
|
Date: 1-July-2008
|
||||||
|
|
||||||
|
- Issue #4. Added an option for setting sorting
|
||||||
|
type behavior when sorting data.
|
||||||
|
Simply set $csv->sort_type to "regular", "numeric",
|
||||||
|
or "string".
|
||||||
|
|
||||||
|
- Issue #6. Raw loaded file data is now cleared from
|
||||||
|
file_data property when it has been successfully
|
||||||
|
parsed to keep parseCSV's memory footprint to a
|
||||||
|
minimum. Specifically handy when using mulitple
|
||||||
|
instances of parseCSV to process large files.
|
||||||
|
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
parseCSV 0.4.2 beta
|
||||||
|
-----------------------------------
|
||||||
|
Date: 31-May-2008
|
||||||
|
|
||||||
|
- IMPORTANT! If you're using the output(),
|
||||||
|
method please note that the first parameter
|
||||||
|
has been completely removed as it was
|
||||||
|
technically just useless. Instead, the second
|
||||||
|
parameter (filename) doubles as its replacement.
|
||||||
|
Simply put, if filename is not set or null, the
|
||||||
|
output() method will not output a downloadable
|
||||||
|
file. Please update your existing code
|
||||||
|
when using 0.4.2 and later :)
|
||||||
|
|
||||||
|
- Small fix to the headers sent by the output()
|
||||||
|
method.
|
||||||
|
|
||||||
|
- Added a download example using the output()
|
||||||
|
method to the examples folder.
|
||||||
|
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
|
||||||
parseCSV 0.4.1 beta
|
parseCSV 0.4.1 beta
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
Date: 29-May-2008
|
Date: 29-May-2008
|
||||||
|
|||||||
12
License.txt
12
License.txt
@@ -1,4 +1,6 @@
|
|||||||
Copyright (c) 2007 Jim Myhrberg (jim@zydev.info).
|
(The MIT license)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Jim Myhrberg.
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -7,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in all
|
||||||
all copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
THE SOFTWARE.
|
SOFTWARE.
|
||||||
|
|||||||
129
README.md
Normal file
129
README.md
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
# parseCSV
|
||||||
|
|
||||||
|
Note: parseCSV is now being revised to PHP 5 standards. If you have an issue or a feature request we encourage you to open an issue.
|
||||||
|
|
||||||
|
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
|
||||||
|
[Wikipedia article][CSV]. It has many advanced features which help make your
|
||||||
|
life easier when dealing with CSV data.
|
||||||
|
|
||||||
|
This library was originaly 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.
|
||||||
|
|
||||||
|
[csv]: http://en.wikipedia.org/wiki/Comma-separated_values
|
||||||
|
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* parseCSV is the only complete and fully featured CSV solution for PHP (as
|
||||||
|
far as I know).
|
||||||
|
* Supports enclosed values, enclosed commas, double quotes and new lines.
|
||||||
|
* Automatic delimiter character detection.
|
||||||
|
* Sort data by specific fields/columns.
|
||||||
|
* Easy data manipulation.
|
||||||
|
* Basic SQL-like _conditions_, _offset_ and _limit_ options for filtering
|
||||||
|
data.
|
||||||
|
* Error detection for incorrectly formatted input. It attempts to be
|
||||||
|
intelligent, but can not be trusted 100% due to the structure of CSV, and
|
||||||
|
how different programs like Excel for example outputs CSV data.
|
||||||
|
* Support for character encoding conversion using PHP's _iconv_ function
|
||||||
|
(requires PHP 5).
|
||||||
|
* Supports both PHP 4 & 5.
|
||||||
|
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
**General**
|
||||||
|
|
||||||
|
```php
|
||||||
|
$csv = new parseCSV('data.csv');
|
||||||
|
print_r($csv->data);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Tab delimited, and encoding conversion**
|
||||||
|
|
||||||
|
```php
|
||||||
|
$csv = new parseCSV();
|
||||||
|
$csv->encoding('UTF-16', 'UTF-8');
|
||||||
|
$csv->delimiter = "\t";
|
||||||
|
$csv->parse('data.tsv');
|
||||||
|
print_r($csv->data);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Auto-detect delimiter character**
|
||||||
|
|
||||||
|
```php
|
||||||
|
$csv = new parseCSV();
|
||||||
|
$csv->auto('data.csv');
|
||||||
|
print_r($csv->data);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Modify data in a CSV file**
|
||||||
|
|
||||||
|
```php
|
||||||
|
$csv = new parseCSV();
|
||||||
|
$csv->sort_by = 'id';
|
||||||
|
$csv->parse('data.csv');
|
||||||
|
# "4" is the value of the "id" column of the CSV row
|
||||||
|
$csv->data[4] = array('firstname' => 'John', 'lastname' => 'Doe', 'email' => 'john@doe.com');
|
||||||
|
$csv->save();
|
||||||
|
```
|
||||||
|
|
||||||
|
**Add row/entry to end of CSV file**
|
||||||
|
|
||||||
|
_Only recommended when you know the extact sctructure of the file._
|
||||||
|
|
||||||
|
```php
|
||||||
|
$csv = new parseCSV();
|
||||||
|
$csv->save('data.csv', array('1986', 'Home', 'Nowhere', ''), true);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Convert 2D array to csv data and send headers to browser to treat output as
|
||||||
|
a file and download it**
|
||||||
|
|
||||||
|
```php
|
||||||
|
$csv = new parseCSV();
|
||||||
|
$csv->output('movies.csv', $array, array('field 1', 'field 2'), ',');
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
* parseCSV is based on the concept of [Ming Hong Ng][ming]'s [CsvFileParser][]
|
||||||
|
class.
|
||||||
|
|
||||||
|
[ming]: http://minghong.blogspot.com/
|
||||||
|
[CsvFileParser]: http://minghong.blogspot.com/2006/07/csv-parser-for-php.html
|
||||||
|
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
Please find a complete list on the project's [contributors][] page.
|
||||||
|
|
||||||
|
[contributors]: https://github.com/parsecsv/parsecsv-for-php/graphs/contributors
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
(The MIT license)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Jim Myhrberg.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
17
composer.json
Normal file
17
composer.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "parsecsv/php-parsecsv",
|
||||||
|
"description": "CSV data parser for PHP",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jim Myhrberg",
|
||||||
|
"email": "contact@jimeh.me"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"autoload": {
|
||||||
|
"classmap": ["."]
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "4.1.*"
|
||||||
|
}
|
||||||
|
}
|
||||||
34
examples/download.php
Normal file
34
examples/download.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
# include parseCSV class.
|
||||||
|
require_once('../parsecsv.lib.php');
|
||||||
|
|
||||||
|
|
||||||
|
# create new parseCSV object.
|
||||||
|
$csv = new parseCSV();
|
||||||
|
|
||||||
|
|
||||||
|
# Parse '_books.csv' using automatic delimiter detection...
|
||||||
|
$csv->auto('_books.csv');
|
||||||
|
|
||||||
|
# ...or if you know the delimiter, set the delimiter character
|
||||||
|
# if its not the default comma...
|
||||||
|
// $csv->delimiter = "\t"; # tab delimited
|
||||||
|
|
||||||
|
# ...and then use the parse() function.
|
||||||
|
// $csv->parse('_books.csv');
|
||||||
|
|
||||||
|
# now we have data in $csv->data, at which point we can modify
|
||||||
|
# it to our hearts content, like removing the last item...
|
||||||
|
array_pop($csv->data);
|
||||||
|
|
||||||
|
# then we output the file to the browser as a downloadable file...
|
||||||
|
$csv->output('books.csv');
|
||||||
|
# ...when the first parameter is given and is not null, the
|
||||||
|
# output method will itself send the correct headers and the
|
||||||
|
# data to download the output as a CSV file. if it's not set
|
||||||
|
# or is set to null, output will only return the generated CSV
|
||||||
|
# output data, and will not output to the browser itself.
|
||||||
|
|
||||||
|
?>
|
||||||
1905
parsecsv.lib.php
1905
parsecsv.lib.php
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user