Reverse reading files
Author: large matrix workshop Joined: 2004-02-19 Views: 100 Some beginners may try to write some text data of the program, and to every record stored as a line (such as guestbook). When writing data, the newly added data may be added to the file. But when reading the file and output, it will be found to be on the old record, the new record is under. So, the new record is output in the following manner below? Very simple, first use the file () function to read all rows of the file as an array, and use the array_reverse () function to reverse the order of each unit of the array. Please see example:
php // assumes that there is data in Data.txt, first define the function $ datafile = 'data.txt'; // use the file () function to read all the rows of the file to $ FN array $ fn = file ($ datafile ); // reverse all units of all units in the array $ DATAS = array_reverse ($ fn); // complete foreach ($ DATAS AS $ DATA) {Echo $ DATA;}?>