My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Examples  
Sample code illustrating how to use the parseCSV class.
Featured, Phase-Implementation
Updated Aug 7, 2007 by zynode

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);
Comment by acumen.d...@gmail.com, Nov 2, 2007

very goog

Comment by you%hane...@gtempaccount.com, Nov 12, 2007

Thank you for this nice PHP class. It does all i want like expected...

Comment by bradpa...@gmail.com, Jan 17, 2008

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!

Comment by Svyatosl...@gmail.com, Jul 30, 2008

Thanks!

Comment by jonathan...@gmail.com, Sep 4, 2008

Brilliant... Thankyou!

Comment by legasthe...@gmail.com, Sep 18, 2008

Thanks! Just nice!

Comment by xpix...@gmail.com, Nov 13, 2008

This class saved my life :) A 1000 Thanks.

Comment by defunct....@gmail.com, Dec 1, 2008

Amazing Class, Thank you for your hard work.

Comment by naunaud...@gmail.com, Feb 17, 2009

Nice work, thank you for sharing!

Comment by Panos...@gmail.com, May 21, 2009

That 's an excellent library. I was really looking for that. God bless you!

Comment by haducch...@gmail.com, Aug 21, 2009

Thanks

Comment by bradbusc...@gmail.com, Aug 28, 2009

Can you reverse the order of the sort?

Comment by reva...@gmail.com, Oct 22, 2009

much appreciated

Comment by ashley.i...@gmail.com, Feb 3, 2010

really good work! very impressive auto detection going on there! Isn't it great when something just works hey ;-)

Comment by mha...@gmail.com, Feb 25, 2010

Nice work

Comment by akais...@gmail.com, Mar 3, 2010

thanks !!!!!1

Comment by cnh...@gmail.com, May 28, 2010

Goog Work, I use it on my Web site Insolite du Geek.

Thanks

Comment by yahya...@gmail.com, Sep 23, 2010

thanks a lot !!!

Comment by dotnetc...@gmail.com, Oct 6, 2010

superb! was able to convert a very slow api export to a csv file in minutes, making myself (and my client) very happy :D kudos!

Comment by yure...@gmail.com, Dec 1, 2010

You are my god My people shall worship thee for eons to come.

Comment by wallacec...@gmail.com, Dec 16, 2010

You can find the detailed information on http://www.phpkode.com

Comment by g1smd.em...@gmail.com, Dec 25, 2010

Thanks!

This code easily knocked 75% off the development time for the http://code.google.com/p/ofcom-csverter/ project.

I never would have figured out how to parse a CSV file while catering for a variety of separators and enclosures.

Comment by arguit...@gmail.com, Feb 18, 2011

I had problems with the page, offset, limit

Comment by patrick....@gmail.com, May 13, 2011

muchas gracias amigo!

Comment by grimwill...@gmail.com, Aug 3, 2011

thanx for this...may prove very useful

Comment by giadii...@gmail.com, Aug 9, 2011

You should change function signatures. output():

$csvHeader = array('Car name', 'color');
$csvData   = array(
    array('Ford', 'black'),
    array('Opel', 'red'),
    );

$csv = new parseCSV();
$csv->output('cars.csv', $csvData, $csvHeader, ',');
Comment by giadii...@gmail.com, Aug 9, 2011

Hmm, maybe because I have 0.4.3 beta.

Comment by kareem...@gmail.com, Jan 4, 2012

I tried this example and it work but on save it create new empty row between my file rows and not any data are saved whyy?

Comment by adrien....@gmail.com, Feb 3, 2012

Thank you :)


Sign in to add a comment
Powered by Google Project Hosting