View Single Post
Old 11-25-2008, 10:43 PM   #1 (permalink)
buildakicker
The Acquainted
 
buildakicker's Avatar
 
Join Date: Jan 2008
Posts: 119
Thanks: 21
buildakicker is on a distinguished road
Default Read Text File in Reverse

Hello all,

I have a text file that contains enteries like so:

Code:
date||name||title||description
I would like to read my file in reverse, ie from the Bottom Up.

I can read it backwards using:

Code:
$file = array_reverse( file( 'u4g.txt' ) );
foreach ( $file as $line ){
ect....

but cannot figure out how EXPLODE each line in a foreach. Why can't I do something like this:

Code:
$file = array_reverse( file( 'u4g.txt' ) );
foreach ( $file as $line ){
	$parts = explode('||', $line);
	echo "<div class='viewline'><h3>" . $parts[3] . "</h3><br />". $parts[4] ."<br />Posted by: " . $parts[1] . "<br /> Date Posted: " . $parts[0] . "<br />" . "Contact Email: " . $parts[2] . "</span></div>";
	}
}
Do I need something like:

Code:
$line_of_text = fgets($fp);
In there???

Thanks!
__________________
SkiLeases.com
buildakicker is offline  
Reply With Quote