Read Data From Text File PHP
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!
Use fopen and fgets, or possibly just file.
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.
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.
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 />";
}
<?php
$myfile = fopen("file_name.txt", "r") or die("Unable to open file!");
// Output one character until end-of-file
while(!feof($myfile)) {
echo fgetc($myfile);
}
fclose($myfile);
?>
You may use this
精彩评论