PHP Application--A complete handbook of Chat Room development (i)

Source: Internet
Author: User
Keywords PHP Application--A complete handbook of Chat Room development (i)

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 the variables passed from the table only son, and handles them as HTML, then Boaster Huan tailed Bird Earwig kohlrabi school irresolute key blow suppression Guanidine Huan shelled? A href= "http://www.beseen.com" target= "_new" > Beseen's chat room is very much like. 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.
  
Now that we have the old message, I want to generate a new message. We've got two variables: $name and $message, so it's easy to write a new message.
  
   ";?>
  
  
We are about to write the good news file. All that is needed is the head information and the foot tag. Add a simple header message first:
  
     
It is important to have a carriage return in addition to the end of the string.
To put all the header information on the same.
$header = "";
  
?>
  
We want the message screen to refresh automatically, so people can see the new posts. Instead of using JavaScript, I refreshed it with a meta tag, mainly because it might be more easily supported by the client. I also don't want the search engine to index my message files. So I'm redefining the letterhead. Lucky D >   
$header = " ".
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.