Joao,
The file() function () reads the specified file into an array line by line. To get the last 30 records you could do something like this:
<?php
// read file data into array
$fileData = file("/path/to/your/data_file.ext");
// loop through the last 30 array keys
for ($x = (count($fileData) - 31) ; $x != count($fileData) ; $x++) {
// buffer line data
$dataBuffer .= $fileData[$x] . "\n"
}
// open the file for writing, place point at EOF
$fp = fopen("/path/to/file/to/write.ext", "ab");
// write all buffered data to file
fputs($fp,$dataBuffer);
// close the open file
fclose($fp);
?>
I've not tested the above code, so your mileage may vary🙂 You'll find the specifics on the functions used above in the Filesystem Functions section of the PHP Manual. HTH.
Geoff A. Virgo