mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 00:36:38 +00:00
Compare commits
80 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 | ||
|
|
20a6a9d1b1 | ||
|
|
70366e3085 | ||
|
|
2dfd35b988 | ||
|
|
ae00f949f0 | ||
|
|
4e76da5eff |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
109
ChangeLog.txt
109
ChangeLog.txt
@@ -1,3 +1,109 @@
|
||||
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
|
||||
-----------------------------------
|
||||
Date: 29-May-2008
|
||||
|
||||
- Fixed a small bug in how the output() method
|
||||
handles input data.
|
||||
|
||||
-----------------------------------
|
||||
|
||||
|
||||
parseCSV 0.4 beta
|
||||
-----------------------------------
|
||||
Date: 11-Apr-2008
|
||||
|
||||
- Error reporting for files/data which is corrupt
|
||||
or has formatting errors like using double
|
||||
quotes in a field without enclosing quotes. Or
|
||||
not escaping double quotes with a second one.
|
||||
|
||||
- parse() method does not require input anymore
|
||||
if the "$object->file" property has been set.
|
||||
|
||||
I'm calling this a beta release due to the heavy
|
||||
modifications to the core parsing logic required
|
||||
for error reporting to work. I have tested the
|
||||
new code quite extensively, I'm fairly confident
|
||||
that it still parses exactly as it always has.
|
||||
|
||||
The second reason I'm calling it a beta release
|
||||
is cause I'm sure the error reporting code will
|
||||
need more refinements and tweaks to detect more
|
||||
types of errors, as it's only picking two types
|
||||
or syntax errors right now. However, it seems
|
||||
these two are the most common errors that you
|
||||
would be likely to come across.
|
||||
|
||||
-----------------------------------
|
||||
|
||||
|
||||
parseCSV 0.3.2
|
||||
-----------------------------------
|
||||
Date: 1-Apr-2008
|
||||
|
||||
This is primarily a bug-fix release for a critical
|
||||
bug which was brought to my attention.
|
||||
|
||||
- Fixed a critical bug in conditions parsing which
|
||||
would generate corrupt matching patterns causing
|
||||
the condition(s) to not work at all in some
|
||||
situations.
|
||||
|
||||
- Fixed a small code error which would cause PHP to
|
||||
generate a invalid offset notice when zero length
|
||||
values were fed into the unparse() method to
|
||||
generate CSV data from an array.
|
||||
|
||||
Notice: If you have been using the "parsecsv-stable"
|
||||
branch as an external in any of your projects,
|
||||
please use the "stable/parsecsv" branch from this
|
||||
point on as I will eventually remove the former due
|
||||
to it's stupid naming.
|
||||
|
||||
-----------------------------------
|
||||
|
||||
|
||||
parseCSV 0.3.1
|
||||
-----------------------------------
|
||||
Date: 1-Sep-2007
|
||||
@@ -31,6 +137,9 @@ Date: 9-Aug-2007
|
||||
- Minor changes and optimizations, and a few
|
||||
spelling corrections. Oops :)
|
||||
|
||||
- Included more complex code examples in the
|
||||
parseCSV download.
|
||||
|
||||
-----------------------------------
|
||||
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
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 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.
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
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.*"
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
rating,title,author,type,asin,tags,review
|
||||
0,The Killing Kind,John Connolly,Book,0340771224,,i still haven't had time to read this one...
|
||||
0,The Third Secret,Steve Berry,Book,0340899263,,need to find time to read this book
|
||||
3,The Last Templar,Raymond Khoury,Book,0752880705,,
|
||||
5,The Traveller,John Twelve Hawks,Book,059305430X,,
|
||||
4,Crisis Four,Andy Mcnab,Book,0345428080,,
|
||||
5,Prey,Michael Crichton,Book,0007154534,,
|
||||
3,The Broker (Paperback),John Grisham,Book,0440241588,book johngrisham,"good book, but is slow in the middle"
|
||||
3,Without Blood (Paperback),Alessandro Baricco,Book,1841955744,,
|
||||
5,State of Fear (Paperback),Michael Crichton,Book,0061015733,,
|
||||
4,The Rule of Four (Paperback),Ian Caldwell,Book,0099451956,book bestseller,
|
||||
4,Deception Point (Paperback),Dan Brown,Book,0671027387,book danbrown bestseller,
|
||||
5,Digital Fortress : A Thriller (Mass Market Paperback),Dan Brown,Book,0312995423,book danbrown bestseller,
|
||||
5,Angels & Demons (Mass Market Paperback),Dan Brown,Book,0671027360,book danbrown bestseller,
|
||||
rating,title,author,type,asin,tags,review
|
||||
0,The Killing Kind,John Connolly,Book,0340771224,,i still haven't had time to read this one...
|
||||
0,The Third Secret,Steve Berry,Book,0340899263,,need to find time to read this book
|
||||
3,The Last Templar,Raymond Khoury,Book,0752880705,,
|
||||
5,The Traveller,John Twelve Hawks,Book,059305430X,,
|
||||
4,Crisis Four,Andy Mcnab,Book,0345428080,,
|
||||
5,Prey,Michael Crichton,Book,0007154534,,
|
||||
3,The Broker (Paperback),John Grisham,Book,0440241588,book johngrisham,"good book, but is slow in the middle"
|
||||
3,Without Blood (Paperback),Alessandro Baricco,Book,1841955744,,
|
||||
5,State of Fear (Paperback),Michael Crichton,Book,0061015733,,
|
||||
4,The Rule of Four (Paperback),Ian Caldwell,Book,0099451956,book bestseller,
|
||||
4,Deception Point (Paperback),Dan Brown,Book,0671027387,book danbrown bestseller,
|
||||
5,Digital Fortress : A Thriller (Mass Market Paperback),Dan Brown,Book,0312995423,book danbrown bestseller,
|
||||
5,Angels & Demons (Mass Market Paperback),Dan Brown,Book,0671027360,book danbrown bestseller,
|
||||
4,The Da Vinci Code (Hardcover),Dan Brown," Book ",0385504209,book movie danbrown bestseller davinci,
|
||||
|
@@ -13,7 +13,11 @@ $csv = new parseCSV();
|
||||
# Parse '_books.csv' using automatic delimiter detection...
|
||||
$csv->auto('_books.csv');
|
||||
|
||||
# ...or if you know the delimiter, use the parse() function.
|
||||
# ...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');
|
||||
|
||||
|
||||
|
||||
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.
|
||||
|
||||
?>
|
||||
1839
parsecsv.lib.php
1839
parsecsv.lib.php
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user