Jump to content

[SOLVED] Counting the lines of a txt file!? please help.


adam1984

Recommended Posts

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."

 

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.