adam1984 Posted June 9, 2009 Share Posted June 9, 2009 I created a form that accepts a user's first and last name, and also a script that saves this data to a text file. After each time a user submits the form, the entry is then written to a new line in my txt document (I'm using the \n to achieve this) That part really wasn't a problem. It's the second half of what I'm trying to do that's causing a little confusion. I want to print a summary that includes the number of lines in my text file, as well as the file's size. You'll see from my code that I have been able to do everything except summarize the number of lines in my text file .Any help would be very much appreciated.. here is the code I am working with, and I thank you in advance: ------------------------------------------------ <?php $filename="people_processed.txt"; $fp = fopen ($filename, "r") or die("Couldn't open $filename"); while (! feof($fp)) { $line = fgets($fp, 1024); print "$line<br />"; } // Below is code that will tell me how // big my file size is getting. print "<br />"; print "<br />"; print "The file size of people_processed.txt is "; print filesize("people_processed.txt"); print " bytes." ?> Quote Link to comment https://forums.phpfreaks.com/topic/161548-solved-counting-the-lines-of-a-txt-file-please-help/ Share on other sites More sharing options...
Maq Posted June 9, 2009 Share Posted June 9, 2009 Try this: $numlines=count(file($filename)); Quote Link to comment https://forums.phpfreaks.com/topic/161548-solved-counting-the-lines-of-a-txt-file-please-help/#findComment-852502 Share on other sites More sharing options...
adam1984 Posted June 9, 2009 Author Share Posted June 9, 2009 That was exactly what I was looking for. Thank you very much for the help, always appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/161548-solved-counting-the-lines-of-a-txt-file-please-help/#findComment-852506 Share on other sites More sharing options...
Maq Posted June 9, 2009 Share Posted June 9, 2009 That was exactly what I was looking for. Thank you very much for the help, always appreciated! Great. Please mark this thread solved. Quote Link to comment https://forums.phpfreaks.com/topic/161548-solved-counting-the-lines-of-a-txt-file-please-help/#findComment-852522 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.