parseCSV 0.3.0 + Google Code
August 13th, 2007
It’s been a long while since i last updated here, life’s been crazy. But i’m not gonna fall into a bottom less pit ranting about everything thats been going on and keeping me busy.
Instead, I’d like to announce parseCSV 0.3.0, my fully featured CSV parser for PHP.
I recently created a Google Code project for parseCSV to bring the class some more attention and spotlight than it’s been getting here dug down in my blog somewhere. I also updated the script to fix a small bug (just plain stupid code), and add some more functionality. Namely, offset and limit options when parsing a CSV file/data. And a basic but very useful conditions option which uses SQL-like syntax to match parsed data for easy filtering.
You can download the script from the project page. The wiki pages are still not really complete, at all, but i’ll get there 
October 4th, 2007 at 2:19 pm
Hi! You did a great job with your csv parser - it is the best parser so far I managed to find on the net. However, I have a question regarding its functioning. I have a csv file which consists of numbers and I need to perform mathematical functions with the last column of this csv file. Literally, I need to choose the rows from the file, which satisfy certain criteria (conditions do an excellent job here), BUT then to multiply every entry in a column by x% and then calculate the sum of all the values in the column. Could you please help me with that? I would really be grateful for your help. Thanks in advance!
October 6th, 2007 at 8:30 pm
Hey Max, if i understand you correctly, what you’re trying to do can’t be done with parseCSV directly, but a quick foreach loop to process the data from parseCSV further, should quickly solve your problem
i emailed you an example (cause wordpress completely butchers the code when pasted into a comment). if you have a list of products with only the base price in the csv data, and you wanna add tax, product total price, and at the same time collect the total, and total with tax price for all products in the specific set of data.
December 14th, 2007 at 4:19 am
I have to say, you are the man! I was going to write my own class to have similar functionality, but then I saw this and never looked back.
Thank you for saving me the time and pain of dealing with M$’s excruciating csv format and for not having to deal with PHP’s crippled fgetcsv() function.
Cheers, mate.
January 11th, 2008 at 9:29 pm
Thank you for making this class available. It has been a great time saver.
January 16th, 2008 at 12:49 pm
Hi
I want to use your parsecsv file but I wanted to ask you how can i fetch the data from mysql db and export it into CSV file using your file?
i have looked around all the files and no where i can see any mysql query, so maybe you can guide me where to put mysql query and fetch the data so that it can be exported to csv.
Thanks
January 17th, 2008 at 6:01 pm
Sati, sorry for the delay, i’ve had some hardware issues with my laptop the last few days…
As for fetching from MySQL, parseCSV has nothing to do with MySQL. It simply takes input data in the form of an array.
However, i’ve also created a lightweight easy to use MySQL class called LiteMySQL. You can use it to fetch your data from a database.
You can find it here: http://code.google.com/p/litemysql/
Sorry for the lack of information about the class, i’ve just been strung on free time lately. But hopefully you’ll manage with the example code available, otherwise, just let me know and i’ll try to help as much as i can
April 1st, 2008 at 9:11 am
Hi,
I need your help i am using your parsecsv file to import 41000 records from a 23mb csv file into database but problem is it hangs in the middle or server starts taking too much load and have to restart apache
can you give some help on how to break the file and import it so it doesnt take too much load on server and import all the records easily?
Thanks
April 4th, 2008 at 4:03 pm
farhan: Sorry for the delay.
I believe the best way to import such a big file is to write a php shell script rather than running it via a web-server. Also, you should import it into a temporary database rather than a mission critical one, just to be on the safe side.
Also, for such a large file, you will most likely have to set php’s memory limit to somewhere above 256MB. If I recall, I once had to set it to 512MB to parse my 11MB iTunes Library.xml file with another script. I’ve never tested parseCSV on such large files tho.
If worst comes to worst, you could always use a texteditor to manually split the file into 1-5MB pieces, altho be careful in that case to not fuck up the csv syntax… lol
If you got any more questions, just leave another comment. And I promise I’ll respond quicker
May 30th, 2008 at 1:30 pm
Hi!
Great job on the CSV parser. I have a question, maybe you know the answer. Whenever I run:
$csv = new parseCSV();
$csv->output (true, ‘contacts.csv’, $c_array);
The resulting CSV file has a blank first line and last line:
1. blank line
2. Name,Phone,Notes
3. John Doe,555-555-5555,He’s a cool guy
4. Jane Doe,333-333-3333,Missing in action
5. blank line
Any ideas on how to get rid of them?
Thanks
Sean
May 30th, 2008 at 2:04 pm
Hi, I figured out that the first blank line was being caused because $heading was set to true. I set it to false, and now the code in function unparse() (the “create heading” code) won’t run.
Thanks
Sean
May 30th, 2008 at 3:59 pm
Sean, it seems like you’re not inputting data the way I originally intended. What’s happening is, that when $object->header is set to true, it just expects there to be header fields in $object->fields, or passed into the output() method as a 4th parameter.
However, due to stupidity, even if there was no header field data anywhere to be found, it’d loop through the $field variable, and then add a line feed to the empty line it thinks its creating.
I’ve fixed this issue, so it now checks if there is any field data, if there isn’t, it wont output a linefeed like you were getting. Just download the new 0.4.1 beta which i just released, and the code you posted above here should work fine
Thanks for telling me about this
May 31st, 2008 at 4:10 am
Hi Jim,
I can confirm that your new 0.4.1 beta code works with $heading = true; No empty lines created in the beginning of the file!
One other thing, I’ve changed line 232 to:
header(’Content-Disposition: attachment; filename=”‘.$filename.’”‘);
I want to be able to download the file, instead of viewing it. Maybe I missed it, but is there an option to specify this?
Thanks for a great library!
Sean
May 31st, 2008 at 9:21 pm
Sean, thanks for the hint, not sure why it had that “inline” header there *whistles innocently*… lol
Anyway, I’ve updated to 0.4.2, and read the ChangeLog, cause I modified the output() method’s input to make it more logical, and less stupid. But it does unfortunately break things in existing code, hence the warning and the beta status
P.S. I think it’d be simpler for both of us if you tell me about further issues through the Issues second on Google Code, as it’s easier to manage than blog comments, and also other users can see what issues/solution/whatever other people have.
Thanks for everything
June 1st, 2008 at 7:49 am
Jim,
Ok I’ll use google code page if I run into any more issues.
Thanks again!
Sean