What is the best practice for reading the last entry in a TXT file using PHP?
To read the last entry in a TXT file using PHP, you can open the file, read its contents line by line, and store the last line in a variable. This can be achieved by using functions like fopen, fgets, and feof in PHP.
$file = fopen("file.txt", "r");
$lastLine = "";
while(!feof($file)) {
$line = fgets($file);
if($line !== false) {
$lastLine = $line;
}
}
fclose($file);
echo $lastLine;