Exemple #1
0
<pre>
<?php 
# include the Parse Interface
require_once '../src/Parse/Csv/ParseInterface.php';
# include parseCSV class.
require_once '../src/Parse/Csv/ParseCSV.php';
# OR use namespace autoloading
//use Parse\Csv\ParseCSV;
# create new parseCSV object.
$csv = new \Parse\Csv\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>
Exemple #2
0
<?php

# include the Parse Interface
require_once '../src/Parse/Csv/ParseInterface.php';
# include parseCSV class.
require_once '../src/Parse/Csv/ParseCSV.php';
# OR use namespace autoloading
//use Parse\Csv\ParseCSV;
# create new parseCSV object.
$csv = new \Parse\Csv\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.