tags:

views:

81

answers:

4

Hi, I'm just wondering how I can read a text file in php, I'd like to have it display the last 200 entries (their each on a new line) from the text file.

Like

John White
Jane Does
John Does
Someones Name

and so on

Thanks!

+2  A: 

Use fopen and fgets, or possibly just file.

Matthew Flaschen
+1  A: 

There are several methods for reading text from files in PHP.

You could use fgets, fread, etc. Load the file into a dynamic array, then just output the last 200 elements of that array.

JYelton
+1  A: 

file will get the contents of a file and put it into an array. After that, it's like JYelton said, output the last 200 elements.

dxprog
A: 

This outputs last 200 rows. Last row first:

$lines = file("filename.txt");
$top200 = array_slice(array_reverse($lines),0,200);
foreach($top200 as $line)
{
    echo $line . "<br />";
}
Vertigo