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 One<a href= ' show.php ' > View message </a> A -<form action= ' doadd.php ' method= ' post ' > -<table width= ' cellpadding= ' > the<tr> -<TD align= ' right ' > title </td> -<td><input type= ' text ' name= ' title ' size= '/></td> -</tr> +<tr> -<TD align= ' right ' > author </td> +<td><input type= ' text ' name= ' author '/></td> A</tr> at<tr> -<TD align= ' right ' > Content </td> -<td><textarea name= ' content ' cols= ' rows= ' 6 ' ></textarea></td> -</tr> -<TR align= ' center ' > -<TD colspan= ' 2 ' > in<input type= ' Submit ' value= ' Add '/> - 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 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