PHP-based chat room (1 ). There used to be a very popular web chat room called StarTrekker. I can come to this chat room to thank a friend of mine, and even if StarTrekker chat room is almost the same as a very popular web chat room I used to have, called the Star Trekker chat room. I can come to this chat room to thank one of my friends, and even if the chat friends of Star Trekker are almost not in the same circle as me, I find that for most of them, both are friendly and interesting. But when Star Trekker is disabled, it has to thank Perl running in the background. it swallowed up server resources, so these happy and friendly people have to leave and go nowhere. I was lucky to have opened my own imitation Star during that time.
Trekker's chat room, and began to try to contact homeless chat friends of many of the original Trekker. Out of vigilance against Perl's resource consumption problems, I was very happy when a friend recommended PHP to me.
This well-designed web chat room uses variables passed from forms, processes them as HTML, and then writes them into files. Put the form and information file in a framework. you can see that it is very similar to a chat room named BeSeen. Of course, its advantages are,
Our chat room is smarter than its BeSeen cousin.
The above is the basic form for input. You may want to make it more beautiful, but for whatever purpose, this is what you want to deal. It sends two variables to chat. php3, namely $ name and $ message.
However, before processing those variables, we need to extract the current content from the message file. Otherwise, we can only see one message at a time. There is almost no way to manage conversations. Only when I am as familiar with the structure of my own message files, I know that each message ends with a carriage return. This means that you can use the file () function to read the message file to an array.
There are 12 message files. In 12 rows, 1st rows contain the header information, 2nd rows to 11 old messages, and 12th rows contain my script.
What I'm most interested in is getting a string that can contain all those old messages.
// Read the file into an array
$ Message_array = file ("messages.html ");
// Edit the string
For ($ counter = 1; $ counter <10; $ counter ++ ){
$ Old_messages. = $ message_array [$ counter];
}
?>
When processing strings, I initialize $ counter of the for loop to 1 instead of 0. This is because I know that the 0th elements in the $ message_array array contain my header information, and I don't need it. The loop end condition is $ counter <10, it means that only the elements 1 to 9 in the array are read into the string. For the remaining two elements, 11th contain my script, and 10th contain the oldest message. I want to delete both of them, because at any time I only want 10 messages to be displayed on the screen. You can modify the $ counter <10 expression to change the number of contained messages.
Your Trekker chat room. I can come to this chat room to thank a friend of mine, and even if the chat friends of Star Trekker are close to me...