The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
The thing that Monkey_Man asked for, got me coding, and trying to make a simple ... v.simpl I should say, lol ... chat site.
Just all the msg's are coming up in the wrong order ... so if you (or anyone else here) know how to put the content of a .dat file into a PHP Variable, lets say $Chat_Text, I'd be greatful :o)
$fp = fopen($Chat_File, 'w'); # Overwrites.
Well, thats what my PHP Book tells me.
I was just wondering if there was a way of addiing to the begining???
Or, maybe putting the whole file into a Variable, adding the know line first and then replacing the variable in the text file, so the new line is put in first, then the old text is put back??? Get what I'm after???
$Text = trim($Text);
if (! empty($Text)) {
$fp = fopen($Chat_File, 'a');
$Time = date("g:ia");
fputs($fp, "\n$Username: $Text ($Time)
");
fclose($fp);
}
thats the part of the code that writes to the file. It includes the Username of the person, there Message and what time it was posted (in a 10:47pm format).
$Chat_File = "Chat_Text.dat";
$Lines = "50"; # How many lines of the chat should be displayed.
$fp = fopen($Chat_File, 'r');
for ($Counter = 1; $Counter <= $Lines; $Counter++) {
$Line = fgets($fp, 1024);
$Line = trim($Line);
print "$Line\n";
}
print "
\n";
fclose($fp);
is the code that reads the first 50 lines of the file, as I don't want every message posted, as that would make the page to big.
Thing is, the message is added to the bottom of the file each time, and I'd prefer it to be added to the top.... so the newer messages are shown :o). Right now, the oldest msg's display first, as they were added to the file first.
Any ideas?
I can do almost what I want .. got the mini-chat site working :o). But the new lines are added to the bottom of the foo.dat file, and I'd prefer them to be added to the top, so the newest lines are at the top, when the script reads the first 50 lines for the chat page ... the new ones are at the top, rather than the old.
Thanks :o)
filesize (foo.dat)
But could I ask what the 26 bit means?