PHP Example 1 simple message board

Source: Internet
Author: User
Tags php example
Note: For more information, see my blog. Example: knowledge points required for a text message board: 1. file Operation: file_put_contents (); file write function file_get_contents (); File Read function 2. string processing function explode (); splits the string into an array

Note: For more information, see my blog. Example: knowledge points required for a text message board: 1. file Operation: file_put_contents (); file write function file_get_contents (); File Read function 2. string processing function explode (); splits the string into an array

Note: For more information, see my blog.

Example: Text message board
Required knowledge points:
1. File Operations:
File_put_contents (); file write function
File_get_contents (); File Reading Function
2. string processing functions
Explode (); a function that splits a string into an array.
Implode (); a function that splits an array to a specified string.
3. Array
Foreach () traverses the Array
Unset () destroy variable
Global Array:
$ _ POST []
$ _ SERVER ["REMOTE_ADDR"]; // obtain the IP address of the client
Time (); // obtain the timestamp of the current system
Date (); date conversion function;
Directory structure:
==========================================
| -- Index. php: page for adding message
|
| -- DoAdd. php: get the message and execute the php file for the add operation.
|
| -- Show. php: display the message page
|
| -- Del. php: interface for deleting message
|
| --Liuyan.txt file used to store message information

Code implementation:

Index. php:

My message board
 
  
Add messages to my message board to View Messages
  Add message
 
Add comments in doAdd. php

My message board
 
  
Add messages to my message board to View Messages
  Add message
  "; // File_put_contents (" liuyan.txt ", $ ly); the output will overwrite the previous message! // 4. The message is successfully output! Echo "message successful! ";?>
 

Show. php Message Display Section:

My message boardScript function dodel (id) {if (confirm ("are you sure you want to delete it? ") {Window. location = 'del. php? Id = '+ id;} script
 
  
Add messages to my message board to View Messages
  View Messages
  

My message board
   
    
Add messages to my message board to View Messages
    Delete message
    
   
= 8) {// 3. split the message with the @ symbol as one (split the message with the @ symbol into a message array) $ lylist = explode ("@@@", $ info); // 4. traverse the message array and parse each message again. foreach ($ lylist as $ k =>$ v) {$ ly = explode ("##", $ v ); echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" ";}}?>Delete del. php messages:
Message Title Contact Message Content IP address Message time Operation
{$ Ly [0]}{$ Ly [1]}{$ Ly [2]}{$ Ly [3]}". Date (" Y-m-d H: I: s ", $ ly [4])."Delete

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.