Read text file reverse using php
Read text file reverse using php
Read text file reverse using php
We are using array_reverse function and read a text file using the regular file(). Once it is read using foreach statement we can assign each line to to a variable $dis_line and print it.
This is how my text.txt file looks like
1 John Deo Four 75 2 Max Ruin Three 85 3 Arnold Three 55 4 Krish Star Four 60 5 John Mike Four 60 6 Alex John Four 55
Create the above file first. Now let us create a PHP file with any name and copy the code below. Save it and run. You will see that the content of the file (text.txt) has been reversed starting with Alex and ending with John. Check out the DEMO for more insight.
$file = file('text.txt'); $read_rev = array_reverse($file); $count=0; foreach ($read_rev as $dis_line) { print_r($dis_line); echo "<br />"; }Read text file reverse using php,