PHP 8.5.0 Alpha 4 available for testing

Voting

: max(seven, one)?
(Example: nine)

The Note You're Voting On

jim at lfchosting dot com
21 years ago
Here is a function that returns the last line of a file. This should be quicker than reading the whole file till you get to the last line. If you want to speed it up a bit, you can set the $pos = some number that is just greater than the line length. The files I was dealing with were various lengths, so this worked for me.

<?php
function readlastline($file)
{
$fp = @fopen($file, "r");
$pos = -1;
$t = " ";
while (
$t != "\n") {
fseek($fp, $pos, SEEK_END);
$t = fgetc($fp);
$pos = $pos - 1;
}
$t = fgets($fp);
fclose($fp);
return
$t;
}
?>

<< Back to user notes page

To Top