GetDotted Domains

Viewing Thread:
"Rob .... HELP (PHP)"

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.

Tue 05/03/02 at 23:45
Regular
Posts: 787
Hey Rob, do you know if and how it's possible to load the content of a .dat file into a PHP Variable???

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)
Thu 07/03/02 at 23:15
Regular
"It goes so quickly"
Posts: 4,083
$fp = fopen($Chat_File, 'a'); # Add's to the end.
$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???
Thu 07/03/02 at 23:11
Regular
"Wasting away"
Posts: 2,230
I'm gonna start taking an interest in this PHP stuff. I've got a book on it, which is about 3 stone heavier then it was when I bought it, due to mass amounts of dust. Although, I might start reading it.....one day.....
Thu 07/03/02 at 23:07
Regular
"Eff, you see, kay?"
Posts: 14,156
Does fputs() append the file then? I though it completely overwrote it.
Thu 07/03/02 at 22:51
Regular
"It goes so quickly"
Posts: 4,083
$Chat_File = "Chat_Text.dat";

$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?
Thu 07/03/02 at 22:46
Regular
"Eff, you see, kay?"
Posts: 14,156
Isn't the order in which the file is written part of your script? How are you writing to it anyway?
Thu 07/03/02 at 22:13
Regular
"It goes so quickly"
Posts: 4,083
How do you mean exactly??
Thu 07/03/02 at 21:08
Regular
"Eff, you see, kay?"
Posts: 14,156
Er.. isn't that a problem with your script?
Thu 07/03/02 at 17:12
Regular
"It goes so quickly"
Posts: 4,083
Some more help with those files things if you can :o)

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)
Wed 06/03/02 at 00:44
Regular
"Eff, you see, kay?"
Posts: 14,156
Oh, er, it's the size of the file to read. I just realised this isn't probably what you want. Replace the 26 with:

filesize (foo.dat)
Wed 06/03/02 at 00:16
Regular
"It goes so quickly"
Posts: 4,083
Yeah Rob .. your good :o)

But could I ask what the 26 bit means?

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Excellent
Excellent communication, polite and courteous staff - I was dealt with professionally. 10/10
LOVE it....
You have made it so easy to build & host a website!!!
Gemma

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.