PHP provides detailed code for implementing the message board function, and php implements the message board function.

Source: Internet
Author: User

PHP provides detailed code for implementing the message board function, and php implements the message board function.

The example in this article shares the Implementation ideas of the php message board for your reference. The specific content is as follows:

1. Create a file name to store the message.

2. Get the data in the form to a variable

3. Identify files that exist

4. Write the file. Before that, when opening the file, select the access method for the file and close the file.

5. Execute read operations on the file. Remember to close the file.

<? Php // message board ideas: 1. create a file name to store the written content. // 2. assign the content in the form to a variable // 3. determine whether the file exists and write the value entered by the user into the variable. When opening the file, be sure to select the file access operation // 4. read the file Content and close the file header ("Content-Type: text/html; charset = utf8"); $ filename = "message.txt "; // create a file name // if the user submits the file, write it to the file and write it in a certain format (isset ($ _ POST ['dosubmit ']) {// use separate fields |, use [n] $ mess = "{$ _ POST ['username']} for separate rows | ". time (). "| {$ _ POST ['title']} | {$ _ POST ['content']} [n]"; writemessage ($ filename, $ mess );/ /Write content to the file} if (file_exists ($ filename) {// determine whether the file has readmessage ($ filename); // read the file function} function writemessage ($ filename, $ mess) {$ fp = fopen ($ filename, "a"); // run the write operation at the end of the file without deleting the original file content fwrite ($ fp, $ mess); // write the file fclose ($ fp); // close the file} function readmessage ($ filename) {$ mess = file_get_contents ($ filename ); $ mess = rtrim ($ mess, "[n]"); $ arrmess = explode ("[n]", $ mess); foreach ($ arrmess as $ m) {list ($ userna Me, $ dt, $ title, $ content) = explode ("|", $ m); echo "<B >{$ username} </B> ,". date ("Y-m-d H: I "). ": <I >{$ title} </I>, <u >{$ content} </u> <br> 

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.