How do I point to the end of a file?

Good morning. I have a tab delimited .txt file that I am trying to read. I currently have the complete file displaying, but I want the last few lines to display only. Any help would be appreciated. Here is the code I have so far.

<?php // find the most current file in the $dir directory $dir = "file/path"; $dh = opendir($dir); $last = 0; $name = " "; while (($file = readdir($dh)) !== false){ if(is_file($dir.$file)){ $mt = filemtime($dir.$file); if($mt > $last){ $last = $mt; $name = $file; } } } closedir($dh); //displays most current file echo "$name " . date ("F d Y H:i:s.", filemtime($dir.$name)); $theFile=fopen($dir.$name,"r"); //run an error check on the variable to make sure we received a data stream if(!$theFile){ print "

Couldn't open the data file. Try again later.

"; } else{ while(!feof($theFile)){ $data=explode("\t", fgets($theFile)); if(sizeof($data)==5){ print "\n"; //enter the column number to print in between the [], starts with 0 print "" . $data[0] . "\n"; print "" . $data[1] . "\n"; print "" . $data[2] . "\n"; print "" . $data[3] . "\n"; print "" . $data[4] . "\n"; print "\n"; } } fclose($theFile); } ?>

I have tried many different methods and can’t get them to work. I am new to PHP and your help and input is appreciated.

Sponsor our Newsletter | Privacy Policy | Terms of Service