I'm just wondering how I can read a text file in php, I would like it to display the last 200 records (each of them in a new line) from a text file.
how
John white Jane does John does Someones name
etc.
Thank!
Use fopen and fgets , or maybe just file .
There are several ways to read text from files in PHP.
fgets, fread .. , 200 .
file will get the contents of the file and put it in an array. After that, as Jalton said, output the last 200 elements.
This displays the last 200 lines. The last line is the 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 can use this
Source: https://habr.com/ru/post/1741343/More articles:How to disable when the user holds control - javascriptHow can I protect my users from session hijacking? - securityHow to close a window (unload NIB)? - cocoaJScrollPanel without scrollbars - javaHow to remove BB codes from a string? - phpWill Apache running on port 8080 prevent dynamically loaded scripts in JavaScript? - javascriptЛучший способ генерации сообщения soap xml? - c#The fastest way to find the sum of digits for large numbers - c ++jQuery hide all rows of a table that contain a hidden field corresponding to a value - jqueryМожет ли интерполяция freemarker содержать интерполяцию? - variablesAll Articles