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.