Example of a text message in PHP (i)

Source: Internet
Author: User
Tags count include key words
As you know, the database is of great importance to the network. Because of the complexity of CGI, now the ASP and Php+mysql have become mainstream. Almost all of the personal web pages have to use the message book, but the application of the message is very unstable. This brings a lot of inconvenience to online communication. Want to have their own message book more and more friends.
However, the free personal homepage supports very few ASP and PHP. I now recommend to you Osso network, (http://www.oso.com.cn) support PHP. So you have the basis to have your own message book. Now, I will use the example of a text message to describe the simple usage of PHP.
First of all, we first determine, the message of a few processes: write a message, send, view. (search) and so on. And for the owner, management message is also indispensable. So we can locate 6 php files, 1 text files. 6 php files are: guest.php manage.php reply.php sys.php del.php edit.php,1 a text file is: guest.txt
First look at the content of guest.php, you can certainly directly put the following content into your PHP page, please respect the author's labor, thank you.
----------------------
guest.php:<?

Require ("sys.php");
if ($B 1)
{
if ($message = = "" or $name = = "")
{
$errorm = "<font color=red> was wrong!!! </font> name and message content must be filled ";
}
Else
{
#写入数据
$space = "";
$time = Date (Y-year m-month D-day H I-hour);
$ip = $REMOTE _addr;
$name =encode ($name);
$homepage =encode ($homepage);
$from =encode ($from);
$email =encode ($email);
$message =stripslashes ($message);
$message =htmlspecialchars ($message);
$message =check_strlen_long ($message);
$message =nl2br ($message);
$guestcontent = "<tr><td><font color= #AB00E1 > Message content:</font><br><!--content>$ message<!--endcontent> ";
$guestcontent = $guestcontent. " <br><font color= #6633FF > Message:</font><!--name> $name <!--endname> ";
if ($email!= "")
{$guestcontent = $guestcontent. " <br><font color= #9900CC > Email </font><a href=\ "mailto: $email \" ><!--email> $email <! --endemail></a> "." $space ";}
if ($homepage!= "http://")
{$guestcontent = $guestcontent. " <font color= #9900CC > Home:</font> $hompage <a href=\ "$homepage \" ><!--homepage> $homepage <!- -endhomepage></a> ";}
$guestcontent = $guestcontent. " <br><font color= #0000FF > Time: $time from:<!--from> $from <!--endfrom> $ip </font> ";
$guestcontent =ereg_replace (CHR), "", $guestcontent);
$guestcontent = $guestcontent. " $FP =fopen ($guestfile, "a");
Fputs ($fp, $guestcontent);
Fclose ($FP);
}
}


?>

<title>zihanonlinegbook</title>
<style>
<!--
a:link {text-decoration:none; color:0000ff}
a:visited {text-decoration:none; color:004080}
a:active {Text-decoration:none}
a:hover {text-decoration:underline; color:ff0000}
Body {font-size:10pt}
TH {font-size:10 pt}
TD {font-size:10pt}
TEXTAREA
{
Font-family: "The song Body";
font-size:10pt;
}

-->
</style>
<body bgcolor= #FFFFFD background= "Bg.jpg" >
<div align= "center" >
? Include (' head.htm ');? >
<table width= "68%" border= "1" cellpadding= "3" cellspacing= "0" bordercolor= "#E3E3E3" >
<form method= "POST" action= "guest.php" >
?
if ($errorm)
{
echo "<tr>";
echo "<td colspan=3 height=32>";
echo "$errorm";
echo "</td>";
echo "</tr>";
}
?>
<tr>
&LT;TD width= "22%" bgcolor= "#F0F0F0" ><font color= "#000000" > Name <font color= "#FF0033" > (required) </font ></font></td>
&LT;TD colspan= "2" width= "78%" bgcolor= "#F0F0F0" ><font color= "#00FF00" >
<input type= "text" name= "name" size= ">"
</font></td>
</tr>
<tr>
&LT;TD width= "22%" height= ">" homepage:</td>
&LT;TD colspan= "2" height= "width=" 78% ">
<input type= "text" name= "homepage" size= "value=" "http://" >
</td>
</tr>
<tr>
&LT;TD width= "22%" height= "bgcolor=" "#F0F0F0" > from:</td>
&LT;TD colspan= "2" height= "a" width= "78%" bgcolor= "#F0F0F0" >
<input type= "text" Name= "from" size= ">"
</td>
</tr>
<tr>
&LT;TD width= "22%" height= ">Email:</td>"
&LT;TD colspan= "2" height= "width=" 78% "><font color=" #00FF00 ">
<input type= "text" name= "email" size= ">"
</font></td>
</tr>
<tr>
&LT;TD colspan= "3" valign= "Middle" align= "left" >
<div align= "center" ><font color= "#000000" > Please leave a message </font><font color= "#FF0033" > (required) </font ><font color= "#00FF00" ><br>
<textarea rows= "6" name= "message" cols= "" wrap= "VIRTUAL" ></textarea>
</font></div>
</td>
</tr>
<tr bgcolor= "#F0F0F0" >
&LT;TD colspan= "3" height= ">"
<div align= "center" ><font color= "#00FF00" >
<input type= "Submit" value= "send" Name= "B1" >

<input type= "reset" value= "rewrite" name= "B2" >
</font></div>
</td>
</tr>
</form>
</table>
<table width= "68%" border= "1" cellpadding= "4" cellspacing= "0" bordercolor= "#E3E3E3" >
<tr>
<td>
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" >
<form action=manage.php method=post>
<tr>
&LT;TD colspan= "2" >
<input Type=hidden Name=dispflag value=show>
Manage Password:
<input Type=password Name=password size=8>

<input type=submit value= "OK" name= "submit" >
</td>
</tr>
</form>
</table>
</td>
<td>
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" >
<form action=guest.php method=post>
<tr>
<td> Please enter the key words:
<input type= "text" name= "keyword" size= "ten" >
<input type= "Submit" name= "search" value= "searching Message" >
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
?
function Search ($keyword)
{
Global $content;
$count =count ($content);
$subscript = 0;
$ArrSearch =array ();
for ($i =0; $i < $count; $i + +)
{
if (Ereg ($keyword, $content [$i])
{
$ArrSearch [$subscript]=ereg_replace ($keyword, "<font color=red> $keyword </font>", $content [$i]);
$subscript + +;
}
}
return $ArrSearch;
}//end function
$one _page_line=15;
$content = file ($guestfile);
if (Isset ($search) and Isset ($keyword) and $keyword!= "")
{
$content =search ($keyword);
}
$count =count ($content);
?>
<table width= "68%" border= "0" >
<tr>
<td>

?
$int _page_count= $count;//total number of articles;
$int _page_num=ceil ($int _page_count/$one _page_line);//total number of pages;
echo "<font color= #CC33FF > Pagination:";
for ($i =1; $i <= $int _page_num; $i + +)
{
echo "<a href=guest.php?page= $i >". $i. " </a> ";
}
echo "</font>";
if (Isset ($search) and Isset ($keyword) and $keyword!= "")
{
echo "<br><center>";
echo "The message below contains the keyword <font color=red> $keyword </font> <font color=red>". $count. " </font> article </center> ";
}
?>
</td><td><p align=right> Total <font color=red><?echo "$count"?></font> strip </p> </td>
</tr>
</table>
</div>
<br>
<table width= "68%" border= "0" align= "center" >
?
if ($page = = "" or!isset ($page))
{$page = 1;}
$text = "";
$begin _line= $int _page_count-($page-1) * $one _page_line;
if ($begin _line< $one _page_line) {$one _page_line= $begin _line;}
for ($j = $begin _line; $j > ($begin _line-$one _page_line); $j--)
{
$text = $text. " &LT;TR&GT;&LT;TD align=right colspan=2><a href=reply.php?job=reply&record= ". $j." > Reply </a> <a href=edit.php?record= ". $j." > Editor </a> <a href=dele.php?record= ". $j." > Delete </a> <font color=red> $j </font> strip </td></tr> ";
$text. = $content [$j-1];

Array to find the subscript starting from 0.
}

echo "$text";
?>
</table>
?
Include (' bottom.htm ');
?>
</body>
------------------
Not to be continued ...


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.