PHP-based chat room (i) _php tutorial

Source: Internet
Author: User
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 ...

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