Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

File line Reversal

Code Wizard, 12-30-2006

This script will reverse the lines in a file. So if you have something that is line based (some newscripts that use flat files) and need to reverse the file line by line for any reason, this will do it.

<?php
$fileLines = file("input.file"); #load file into a variable
$i = count($fileLines); #count the lines in the file
$cnt = $i; #change $i to $cnt
touch("output.file"); #create output file
$fp=fopen("input.file", 'r'); #load file into file pointer
for(;$cnt >= 0;$cnt--) #count down statment line by line loop
{
fputs ($fp,"$fileLines[$cnt]"); #put the line to the file
}
fclose($fp); #close file pointer's file
echo "Done Reversing."; #done!
?>
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions