Lyleyboy Posted January 22, 2007 Share Posted January 22, 2007 Hi all,Just wondering if you can assist me with this one. I have a csv file that is constantly added to. I need to be able to count how many entries are in the file.Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2007 Share Posted January 22, 2007 [code]<?php $count = count(explode(',',file_get_contents('file.scv')));?>[/code] Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted January 22, 2007 Author Share Posted January 22, 2007 Thanks mate. Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted January 22, 2007 Author Share Posted January 22, 2007 This returns a value of 16. There are two lines in the csv.Any idea's Quote Link to comment Share on other sites More sharing options...
Nelak Posted January 22, 2007 Share Posted January 22, 2007 if u have lots of commas in the file it will count loads of entries. Use a character which is not used in your file and put it on the end of entry.[code]explode('CHARACTER HERE',file_get_contents('file.scv')));[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 22, 2007 Share Posted January 22, 2007 Do you want to count the lines or the comma seperated values? If its just the lines use...[code]<?php $count = count(file('file.csv'));?>[/code] Quote Link to comment Share on other sites More sharing options...
Lyleyboy Posted January 22, 2007 Author Share Posted January 22, 2007 Cheers Thorpe. It seems one of the other version I had tried was adding commas to the end of the file and hence screwing it all up. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.