|
|
Examples
Sample code illustrating how to use the parseCSV class.
General:
$csv = new parseCSV('data.csv');
print_r($csv->data);Tab delimited, and encoding conversion:
$csv = new parseCSV();
$csv->encoding('UTF-16', 'UTF-8');
$csv->delimiter = "\t";
$csv->parse('data.tsv');
print_r($csv->data);Auto-detect delimiter character:
$csv = new parseCSV();
$csv->auto('data.csv');
print_r($csv->data);Modify data in a CSV file:
$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.
$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:
$csv = new parseCSV(); $csv->output (true, 'movies.csv', $array);
Sign in to add a comment

very goog
Thank you for this nice PHP class. It does all i want like expected...
Thanks so much for your work, and for generously putting this out there as opensource. I needed to do just this myself, and searched PEAR for a CSV parser, but was surprised to see none available. Thanks again!
Thanks!