PHP text Message Board--php Classic example

Source: Internet
Author: User
Tags array to string explode rtrim

File structure:

index.php home page and add page

show.php View Message page

Ly.db Text Save page

doadd.php Add Features Page

dodel.php Delete Features page

index.php

123<title> Text-Message board </title>4<meta charset= ' Utf-8 '/>56<body>7<center>89<a href= ' index.php ' > Add a message </a>Ten&nbsp;&nbsp;&nbsp;&nbsp; One<a href= ' show.php ' > View message </a> A -<form action= ' doadd.php ' method= ' post ' > -<table width= ' cellpadding= ' > the<tr> -&LT;TD align= ' right ' > title </td> -<td><input type= ' text ' name= ' title ' size= '/></td> -</tr> +<tr> -&LT;TD align= ' right ' > author </td> +<td><input type= ' text ' name= ' author '/></td> A</tr> at<tr> -&LT;TD align= ' right ' > Content </td> -<td><textarea name= ' content ' cols= ' rows= ' 6 ' ></textarea></td> -</tr> -&LT;TR align= ' center ' > -&LT;TD colspan= ' 2 ' > in<input type= ' Submit ' value= ' Add '/> -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to<input type= ' reset ' value= ' empty '/> +</td> -</tr> the</table> *</form> $</center>Panax Notoginseng</body> -

show.php

123<title> Text-Message board </title>4<meta charset= ' Utf-8 '/>56<body>7<center>89<a href= ' index.php ' > Add a message </a>Ten&nbsp;&nbsp;&nbsp;&nbsp; One<a href= ' show.php ' > View message </a> A -              -<table width= ' border= ' 1 ' cellpadding= ' 5 ' > the<tr> -<th> title </th> -<th> author </th> -<th> content </th> +<th>i p</th> -<th> Time </th> +<th> Operations </th> A</tr> at<?PHP -                     //Read the file -                     $info=RTrim(file_get_contents("Ly.db"), "@"); -                     if($info!= ""){ -                         //Split -                         $list=Explode("@@",$info); in                          -                         //Var_dump ($list); to //Traversal +                         foreach($list  as $k=$v){ -                          the                             //Split v *                             $oncely=Explode("##",$v); $ Panax Notoginseng                             Echo"<tr>"; -                                 Echo"<td>{$oncely[0]} </td> "; the                                 Echo"<td>{$oncely[1]} </td> "; +                                 Echo"<td>{$oncely[2]} </td> "; A                                 Echo"<td>{$oncely[3]} </td> "; the                                 Echo"<td>{$oncely[4]} </td> "; +                                 Echo"<td><a href= ' dodel.php?k={$k} ' > Delete </a></td> '; -                             Echo"</tr>"; $                         } $                      -}Else{ -                         Echo"No Data"; the                     } -                     Wuyi                  the                  -?> Wu</table> -          About</center> $</body> -

doadd.php

1<?PHP2     if(Empty($_post)){3         //If the post submission is not automatically jumped back4         Header("location:index.php");5          die;6     }7     //title cannot be empty8     if($_post[' title ']== ']){9         Echo"The title cannot be empty!" ";Ten         Header("refresh:1;url=index.php"); One          die; A     } -     //The author cannot be empty -     if($_post[' Author ']== ' ""){ the         Echo"The author cannot be empty!" "; -         Header("refresh:1;url=index.php"); -          die; -     } +     //content cannot be empty -     if($_post[' Content ']== ' "){ +         Echo"The content cannot be empty!" "; A         Header("refresh:1;url=index.php"); at          die; -     } -      -     //Stitching Strings -     $info=$_post[' title ']. ##".$_post[' Author ']. " ##".$_post[' content ']. -"##".$_server[' REMOTE_ADDR ']. " ##".Date("Y-m-d h:i"). " @@"; in      -     //write to db file to     file_put_contents("Ly.db",$info,file_append); +      -     Echo"OK"; the     Header("refresh:1;url=index.php"); *      $     Panax Notoginseng  -?>

dodel.php

1<?PHP2 3     if(!isset($_get[' K '])){4         //K didn't pass up and jumped right back.5         Header("location:show.php");6          die;7     }8     9     $k=$_get[' K '];Ten      One     //Read the file A     $info=RTrim(file_get_contents("Ly.db"), "@"); -      -     //Split the     $list=Explode("@@",$info); -      -     //Delete -     unset($list[$k]); +      -     if(Count($list) >0){ +         //array to string backfill to db file A         file_put_contents("Ly.db",implode("@@",$list)." @@"); at}Else{ -         //the array is empty backfill a null character -         file_put_contents("Ly.db", "" "); -     } -      -     Echo"OK"; in     Header("refresh:1;url=show.php");  -  to?>

: Http://files.cnblogs.com/files/wordblog/wblyb.zip

PHP text message board--php Classic instance

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.