Tutorials | Application examples based on PHP chat room (i)
This well-designed web chat room uses variables that are passed from the table conveys and processes them as HTML and then writes them to the file. Put the form and the information file in a frame, and you can see it is like a chat room called Beseen. The good thing about it, of course, is that our chat room is smarter than its beseen cousins.
The above is the basic form for input. You may want to make it a little more beautiful, but for whatever purpose, this is what you have to deal with. It sends two variables to CHAT.PHP3, respectively called $name and $message.
However, before dealing with those variables, we need to remove the current contents from the message file, otherwise we will see only one message at a time. There is hardly a way to manage conversations. Just as I am familiar with the structure of my own message file, 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 lines. In line 12, the 1th Act header information, line 2nd to 11 acts the old message, and the 12th line contains my foot mark.
What I am most interested in is getting a string that can contain all those old messages.
<?php
Read the file into an array
$message _array = File ("messages.html");
When dealing 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 don't need it. Also, by setting the loop end condition to $counter < 10, it means that only elements 1 to 9 of the array are read into the string. For the remaining two elements, the 11th contains my pin, and the 10th contains the oldest message. Both of these I want to delete, because at any moment I only let the screen display 10 messages. Modifying the $counter < 10 expression allows you to change the number of messages contained.
Now that I 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.
<?php $new _message = "$name: $message <br>";?>
We are about to write a good news file. All that is left is the header information and the foot sign. First add a simple header message:
<?php
In addition to having a carriage return at the end of the string, it is important that no carriage return be available elsewhere.
To put all the head information in the same.
$header = "
?>
We want the message screen to be refreshed automatically, so people can see the new posts. Instead of using JavaScript, I used a meta tag to refresh, mainly because it might be easier for clients to support it. I also don't want the search engine to index my message files. So redefine header information as:
Using the copyright information in <font color= "#000000 >" means that it is only visible if it is selected because it is #000000 the same color as the background color. This is done only to keep it from affecting the display.
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.