Looks like you got the order a bit messed up.
You are putting the lines into the array while you are printing them, which makes no sense.
You should first read all the lines into an array, and then print them, or forget the array, and just print the lines immediately:
<?
$display = "5";
$file = fopen ("posts.txt","r");
while (!feof ($file))
{
$lines[] = fgets ($file, 4098);
};
if (count($lines)<$display)
{
$display = count($lines);
};
for ($i=0; $i < $display; $i++)
{
list($title,$news,$username)=explode("|", $lines[$i]);
print "title: $title<br>news: $news<br>username: $username<br><br>";
} ;
?>
or
<?
$display = "5";
$file = fopen ("posts.txt","r");
$i=0;
while ((!feof ($file)) && ($i++<5))
{
$line = fgets ($file, 4098);
list($title,$news,$username)=explode("|", $line);
print "title: $title<br>news: $news<br>username: $username<br><br>";
};
?>