PHP application-full manual for chatting room development (1) _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP application-full manual for chatting room development (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 resource consumption caused by Perl, I am very happy when a friend recommends php (as a mainstream development language) to me.
  
This well-designed web chat room uses the variables passed from the form, and processes them as HTML. Then, when the variables are transferred, the keys are used to blow the keys? A href = "http://www.beseen.com" target = "_ new"> BeSeen's chat room is very similar. 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. php (as the mainstream development language) 3, called $ name and $ message respectively.
  
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.
  
Now that old messages are available, I want to generate new messages. We already have two variables: $ name and $ message, so it is easy to write a new message.
  
   ";?>
  
  
We are about to write a good news file. The rest is the header information and the script. First, add a simple header information:
  
     
// Except for carriage return at the end of the string, carriage return is not allowed in other places, which is very important.
// Put all header information in the same way.
$ Header ="";
  
?>
  
We want the message screen to be automatically refreshed so that people can see new posts. Instead of using JavaScript, I used META tags for refresh, mainly because it may be more easily supported by clients. I also don't want the search engine to index my message files. So I want to redefine my first letter of confidence? Lucky? Lucky D>   
$ Header =" ".

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...

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.