83 Commits
0.2.1 ... 0.4.5

Author SHA1 Message Date
William Knauss
0486a4bf3e Merge pull request #18 from parsecsv/williamknauss-new-issue-14
williamknauss new issue 14
2014-06-02 20:37:04 -04:00
William Knauss
90042a553c ugh 2014-06-02 20:35:20 -04:00
William Knauss
73d7acb493 fix conflicts 2014-06-02 20:34:08 -04:00
William Knauss
7b6692d7fd @norcoen caching request 2014-06-02 20:13:31 -04:00
William Knauss
01d25e0fdd Tabs to spaces 2014-06-02 20:09:20 -04:00
William Knauss
c64a4bffd7 Merge pull request #12 from williamknauss/tab_to_spaces
Fix #11
2014-05-17 12:51:24 -04:00
William Knauss
2d7f18ebc9 converted tabs to spaces 2014-05-17 12:47:45 -04:00
William Knauss
ee5b34e1c1 Merge branch 'master' of https://github.com/parsecsv/parsecsv-for-php 2014-05-17 12:43:00 -04:00
William Knauss
44929708ca Merge pull request #10 from parsecsv/fix-author-name-spelling
Fix typo in author name
2014-05-17 12:41:36 -04:00
c55ab2ec2c Fix typo in author's last name 2014-05-17 10:50:01 +01:00
William Knauss
6784c614ea Merge pull request #2 from parsecsv/master
Fork Update
2014-05-16 19:49:55 -04:00
William Knauss
5a70a7bffa Merge pull request #9 from williamknauss/composer-support
Composer support
2014-05-16 19:37:46 -04:00
William Knauss
c1a6946815 added gitignore 2014-05-16 19:33:15 -04:00
William Knauss
dbf415bd92 Added Composer.json 2014-05-16 19:30:59 -04:00
William Knauss
c915579955 Merge pull request #8 from williamknauss/readme_update-1
Readme update
2014-05-16 17:36:59 -04:00
William Knauss
55aaa1eb17 Grammer Fix 2014-05-16 17:36:14 -04:00
William Knauss
ab069e5d2d Updated readme 2014-05-16 17:35:08 -04:00
William Knauss
7e7aeba761 Merge pull request #6 from williamknauss/issue-5
Issue 5
2014-05-14 10:29:48 -04:00
William Knauss
a3e3582222 Patch for #5 2014-05-14 10:26:32 -04:00
William Knauss
fff3e73f08 Merge pull request #1 from parsecsv/master
U2D
2014-05-14 10:20:18 -04:00
f59af53183 Add contributors section to readme 2014-05-14 14:50:10 +01:00
629b0c9fd5 Indent header comment start/end strings 2014-05-14 10:18:02 +01:00
698a570a11 Add license header 2014-05-14 10:12:45 +01:00
2aca09e05d Add URL to PHP class which inspired parseCSV's creation 2014-05-14 09:26:21 +01:00
7a9fc101f8 Update copyright year in readme and license file 2014-05-14 09:24:27 +01:00
a1564a9a99 Correct project URL, and update copyright 2014-05-14 09:19:42 +01:00
4b280885f4 Merge pull request #1 from williamknauss/master
Basic Cleanup
2014-05-14 09:14:26 +01:00
William Knauss
88ad81f061 removed end of php line
its not really needed
2014-05-13 21:26:06 -04:00
William Knauss
7e46cc193a line feed should only be \r 2014-05-13 21:23:53 -04:00
William Knauss
a274874084 documenation changes 2014-05-13 21:23:23 -04:00
William Knauss
dea1b453eb _validate_row_conditions readability 2014-05-13 21:21:58 -04:00
William Knauss
9a8bd77eb8 forgot access flag 2014-05-13 21:21:04 -04:00
William Knauss
89a2817765 _validate_row_condition readability 2014-05-13 21:19:44 -04:00
William Knauss
75d7d51a9c _validate_offset readability 2014-05-13 21:05:53 -04:00
William Knauss
9b6dbd9849 _enclose_value readability 2014-05-13 21:05:11 -04:00
William Knauss
61d1c27eac _check_data readability 2014-05-13 21:04:25 -04:00
William Knauss
ecbb0736f1 more changes 2014-05-13 18:56:26 -04:00
William Knauss
2ab7625bb5 _rfile readability 2014-05-13 18:24:31 -04:00
William Knauss
0f39cfa75a _wfile readability 2014-05-13 18:23:27 -04:00
William Knauss
0457fbfba2 removed back comments 2014-05-13 18:22:18 -04:00
William Knauss
af5d7cf70d load_data readability 2014-05-09 21:57:17 -04:00
William Knauss
531cc66a5e unparse readability 2014-05-09 21:55:54 -04:00
William Knauss
178699580e unparse readability 2014-05-09 21:55:36 -04:00
William Knauss
8c300568bb parse_string readability 2014-05-09 21:54:09 -04:00
William Knauss
28967dea20 extra space 2014-05-09 21:46:11 -04:00
William Knauss
46b42776e4 Properties documentation 2014-05-09 21:45:03 -04:00
William Knauss
8ba88c582d removed documentation whitespace 2014-05-09 21:31:22 -04:00
William Knauss
ba1d462044 updated properties to "public"
removed "var" and set to "public"
2014-05-09 21:30:47 -04:00
William Knauss
0323d5108b parse_file documentation 2014-02-06 18:31:34 -05:00
William Knauss
2988278f0b parse_file readability 2014-02-06 18:30:43 -05:00
William Knauss
9301b016c8 auto documentation 2014-02-06 18:30:11 -05:00
William Knauss
75038f9d2f auto readability 2014-02-06 18:27:54 -05:00
William Knauss
b72385395e condition spacing 2014-02-06 08:17:00 -05:00
William Knauss
eb3c9faa4a construct docblock spacing 2014-02-05 19:16:51 -05:00
William Knauss
2f142e7313 public encoding 2014-02-05 19:16:35 -05:00
William Knauss
05dbcaf652 encoding update 2014-02-05 19:14:00 -05:00
William Knauss
4639fa1701 Output documentation 2014-02-05 19:12:16 -05:00
William Knauss
8bb8e2d7cf output readability 2014-02-05 19:09:57 -05:00
William Knauss
c7e1f825a0 save documentation 2014-02-05 18:41:21 -05:00
William Knauss
0638049fb2 save readability 2014-02-05 18:38:55 -05:00
William Knauss
585a0d472e parse documentation 2014-02-05 18:37:23 -05:00
William Knauss
d6a070ce08 Change __constructor docblock stype 2014-02-05 18:33:44 -05:00
William Knauss
4454196b4c parse readability 2014-02-05 18:31:27 -05:00
William Knauss
6a6754ca04 __construct documentation 2014-02-05 18:29:01 -05:00
William Knauss
8dd2e52073 __construct readability 2014-02-05 18:25:13 -05:00
William Knauss
e16d818d07 cleaned up construct 2014-02-05 18:24:41 -05:00
William Knauss
9e6fdbb42a Updated project link 2014-02-05 18:22:20 -05:00
85ca7af160 Update License.txt file 2014-02-05 21:18:07 +00:00
1b91591d32 Add readme 2014-02-05 21:16:50 +00:00
zynode
dfe298f4d0 Fixed a typo in the header comment regarding example code.
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@44 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-11-17 15:48:46 +00:00
zynode
fc22bee7ca parseCSV 0.4.3 beta
- 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.

git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@41 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-06-30 21:41:42 +00:00
zynode
9b64cb07c4 Fixed Issue #6 - Automatically clears $file_data property after successful parsing of input data. Set the $keep_file_data property to true to keep it around for debugging.
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@39 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-06-30 20:38:59 +00:00
zynode
2bfa3de220 Addressed Issue #4. Added option for sorting behavior type.
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@38 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-06-30 20:01:50 +00:00
zynode
c522cd87a7 fixed a small changelog typo in the 0.4.2 trunk and tag
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@36 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-05-31 18:12:15 +00:00
zynode
0395362d66 parseCSV 0.4.2
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@34 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-05-31 17:59:21 +00:00
zynode
20a6a9d1b1 parseCSV 0.4.1 beta
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@31 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-05-30 12:20:39 +00:00
zynode
70366e3085 parseCSV 0.4 beta
- 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.

git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@28 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-04-11 18:13:37 +00:00
zynode
2dfd35b988 added error reporting/validation of parsed data, still needs some more testing before release tho...
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@27 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-04-07 16:17:44 +00:00
zynode
ae00f949f0 parseCSV 0.3.2
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.

git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@22 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-03-31 22:50:36 +00:00
zynode
4e76da5eff minor fix to a bug which caused notice errors to be generated when _enclose_value() was fed a zero character long string
git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@20 339761fc-0c37-0410-822d-8b8cac1f6a97
2008-03-31 20:55:33 +00:00
zynode
7762e71316 parseCSV 0.3.1
- Small change to default output settings to
  conform with RFC 4180 (http://rfc.net/rfc4180.html).
  Only the LF (line feed) character was used
  by default to separate rows, rather than
  CRLF (carriage return & line feed).

git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@17 339761fc-0c37-0410-822d-8b8cac1f6a97
2007-08-31 22:45:22 +00:00
zynode
e28b3d0f9d parseCSV 0.3.0
- Changed to the MIT license.

- Added offset and limit options.

- Added SQL-like conditions for quickly
  filtering out entries. Documentation on the
  condition syntax is forthcoming.

- Small parsing modification to comply
  with some recent changes to the specifications
  outlined on Wikipedia's Comma-separated values
  article.

- Minor changes and optimizations, and a few
  spelling corrections. Oops :)

git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@14 339761fc-0c37-0410-822d-8b8cac1f6a97
2007-08-09 09:17:54 +00:00
zynode
9c389ed0c1 conditions, limit and offset are functional. conditions needs a rewrite tho.
added examples to trunk.


git-svn-id: http://parsecsv-for-php.googlecode.com/svn/trunk@13 339761fc-0c37-0410-822d-8b8cac1f6a97
2007-08-08 18:48:11 +00:00
11 changed files with 1678 additions and 550 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
vendor/
composer.lock

View File

@@ -1,3 +1,148 @@
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
- Small change to default output settings to
conform with RFC 4180 (http://rfc.net/rfc4180.html).
Only the LF (line feed) character was used
by default to separate rows, rather than
CRLF (carriage return & line feed).
-----------------------------------
parseCSV 0.3.0
-----------------------------------
Date: 9-Aug-2007
- Changed to the MIT license.
- Added offset and limit options.
- Added SQL-like conditions for quickly
filtering out entries. Documentation on the
condition syntax is forthcoming.
- Small parsing modification to comply
with some recent changes to the specifications
outlined on Wikipedia's Comma-separated values
article.
- Minor changes and optimizations, and a few
spelling corrections. Oops :)
- Included more complex code examples in the
parseCSV download.
-----------------------------------
parseCSV 0.2.1
-----------------------------------
Date: 8-Aug-2007

21
License.txt Normal file
View File

@@ -0,0 +1,21 @@
(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.

129
README.md Normal file
View 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
View 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.*"
}
}

15
examples/_books.csv Normal file
View File

@@ -0,0 +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,
4,The Da Vinci Code (Hardcover),Dan Brown," Book ",0385504209,book movie danbrown bestseller davinci,
1 rating title author type asin tags review
2 0 The Killing Kind John Connolly Book 0340771224 i still haven't had time to read this one...
3 0 The Third Secret Steve Berry Book 0340899263 need to find time to read this book
4 3 The Last Templar Raymond Khoury Book 0752880705
5 5 The Traveller John Twelve Hawks Book 059305430X
6 4 Crisis Four Andy Mcnab Book 0345428080
7 5 Prey Michael Crichton Book 0007154534
8 3 The Broker (Paperback) John Grisham Book 0440241588 book johngrisham good book, but is slow in the middle
9 3 Without Blood (Paperback) Alessandro Baricco Book 1841955744
10 5 State of Fear (Paperback) Michael Crichton Book 0061015733
11 4 The Rule of Four (Paperback) Ian Caldwell Book 0099451956 book bestseller
12 4 Deception Point (Paperback) Dan Brown Book 0671027387 book danbrown bestseller
13 5 Digital Fortress : A Thriller (Mass Market Paperback) Dan Brown Book 0312995423 book danbrown bestseller
14 5 Angels & Demons (Mass Market Paperback) Dan Brown Book 0671027360 book danbrown bestseller
15 4 The Da Vinci Code (Hardcover) Dan Brown Book 0385504209 book movie danbrown bestseller davinci

48
examples/basic.php Normal file
View File

@@ -0,0 +1,48 @@
<pre>
<?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');
# Output result.
// print_r($csv->data);
?>
</pre>
<style type="text/css" media="screen">
table { background-color: #BBB; }
th { background-color: #EEE; }
td { background-color: #FFF; }
</style>
<table border="0" cellspacing="1" cellpadding="3">
<tr>
<?php foreach ($csv->titles as $value): ?>
<th><?php echo $value; ?></th>
<?php endforeach; ?>
</tr>
<?php foreach ($csv->data as $key => $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?php echo $value; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>

48
examples/conditions.php Normal file
View File

@@ -0,0 +1,48 @@
<pre>
<?php
# include parseCSV class.
require_once('../parsecsv.lib.php');
# create new parseCSV object.
$csv = new parseCSV();
# Example conditions:
// $csv->conditions = 'title contains paperback OR title contains hardcover';
$csv->conditions = 'author does not contain dan brown';
// $csv->conditions = 'rating < 4 OR author is John Twelve Hawks';
// $csv->conditions = 'rating > 4 AND author is Dan Brown';
# Parse '_books.csv' using automatic delimiter detection.
$csv->auto('_books.csv');
# Output result.
// print_r($csv->data);
?>
</pre>
<style type="text/css" media="screen">
table { background-color: #BBB; }
th { background-color: #EEE; }
td { background-color: #FFF; }
</style>
<table border="0" cellspacing="1" cellpadding="3">
<tr>
<?php foreach ($csv->titles as $value): ?>
<th><?php echo $value; ?></th>
<?php endforeach; ?>
</tr>
<?php foreach ($csv->data as $key => $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?php echo $value; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>

34
examples/download.php Normal file
View 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.
?>

61
examples/limit.php Normal file
View File

@@ -0,0 +1,61 @@
<pre>
<?php
# include parseCSV class.
require_once('../parsecsv.lib.php');
# create new parseCSV object.
$csv = new parseCSV();
# if sorting is enabled, the whole CSV file
# will be processed and sorted and then rows
# are extracted based on offset and limit.
#
# if sorting is not enabled, then the least
# amount of rows to satisfy offset and limit
# settings will be processed. this is useful
# with large files when you only need the
# first 20 rows for example.
$csv->sort_by = 'title';
# offset from the beginning of the file,
# ignoring the first X number of rows.
$csv->offset = 2;
# limit the number of returned rows.
$csv->limit = 3;
# Parse '_books.csv' using automatic delimiter detection.
$csv->auto('_books.csv');
# Output result.
// print_r($csv->data);
?>
</pre>
<style type="text/css" media="screen">
table { background-color: #BBB; }
th { background-color: #EEE; }
td { background-color: #FFF; }
</style>
<table border="0" cellspacing="1" cellpadding="3">
<tr>
<?php foreach ($csv->titles as $value): ?>
<th><?php echo $value; ?></th>
<?php endforeach; ?>
</tr>
<?php foreach ($csv->data as $key => $row): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?php echo $value; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</table>

File diff suppressed because it is too large Load Diff