There used to be a rather popular web chat room called star Trekker chat room. I was able to come to this chat room to thank a friend of mine, and even though star Trekker's friends were almost not in the same circle as me, I found it was friendly and interesting for most of them. But when star Trekker shut down, it had to thank Perl, which was running in the background, to swallow the resources of the server, so the happy and friendly people had to leave and nowhere to go. I had the pleasure of opening my own imitation star during that period.
Trekker's chat room and began trying to connect with many of the old Trekker's homeless friends. Being wary of the problem of resource consumption caused by Perl, I was very happy when a friend suggested PHP to me.
This well-designed web chat room uses variables passed from table only son, processes them as HTML, and writes them to the file. Put the form and information file in a frame, you can see it is like a chat room called Beseen. Of course, the advantage of it is that
Our chat room is smarter than its beseen cousins.
Above is the basic form for input. You might want to make it look more beautiful, but for whatever purpose, this is what you're dealing with. It sends two variables to CHAT.PHP3, called $name and $message, respectively.
However, before dealing with those variables, we need to remove the current content from the message file, otherwise we can only see one message at a time. There is hardly a way to manage conversations. Only as I am familiar with the structure of my own message files, I know that every message ends with a carriage return. This means that you can use the file () function to read a message file into an array.
The message file has 12 rows. In 12 rows, the 1th behavior header information, line 2nd to 11 behaves old messages, and line 12th contains my foot markers.
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 String
for ($counter = 1; $counter < $counter + +) {
$old _messages. = $message _array[$counter];
}
?>
When working with strings, I initialize the $counter for the For loop to 1 instead of 0. This is because I know that the No. 0 element of the $message_array array contains my header information and I do not need it to loop the end condition to $counter < 10, meaning that only the elements from 1 to 9 in the array are read into the string. For the remaining two elements, the 11th one contains my feet, and the 10th contains the oldest messages. Both of these I want to delete because at any moment I only let the screen show 10 messages. Modifying the $counter < 10 expression allows you to change the number of messages contained.
http://www.bkjia.com/PHPjc/445185.html www.bkjia.com true http://www.bkjia.com/PHPjc/445185.html techarticle there used to be a rather popular web chat room called star Trekker chat room. I was able to come to this chat room to thank a friend of mine, and even if star Trekker's chat friends were almost with me ...