[快速入口区]  没泪水的泪眼 | 落泪的百合  |  风过留痕 | 风枫轩 |  美文欣赏  |  红袖文学  |  潇湘琴韵文集收藏   |   九九文章网   |  网站优化  |  PHP 学习区  | 需求分析 欢迎大家来聚!

曾经沧海难为水 除却巫山不是云

    朋友就是无形中伴你走过风雨,永远支持你的力量 朋友就是一种无法言喻的美好感觉 朋友就是在别人面 前永远护著你的那个人 朋友就是即使是一点小感动,一点小事情都想一起分享 朋友就是当你抱头痛哭的时候,扶著你肩膀的那个人 朋友就是当你面对人生挫折时,一直紧握你的那双手 喜欢下雨,因为你不会知道我流泪…… 你能够看到他是你与他的缘份 你能够和你身边的人做朋友也是你与他的缘份 纵使你不知道这颗流星会何时消失 但如若你好好珍惜看到这流星的每一刻 那就算流星走了你也不会后悔 请大家好好珍惜身边的每一个人 珍惜这段友谊!

广告位招租:[ 中国图书网   |  京东商城  | 健康平安网  | C I 2.1手册 ]

导航

用php来开发一个仿百度搜索引擎

搜索页面代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">

body,td,.p1,.p2,.i{ font-family:arial; }
body{margin:6px 0 0 0;background-color:#fff;color:#000;}
table{border:0}
a.t:hover{TEXT-DECORATION:underline}
.f{line-height:100%;font-size:100%;width:43em;padding-left:15px;word-break:break-all;word-wrap:break-word;}
.Tit {height:21px; font-size:14px;}
.fB {font-weight:bold;}
.i1 {font-size:16px}
.bi {background-color:#D9E1F7;height:20px;margin-bottom:12px}
.p{padding-left:18px;font-size:14px;word-spacing:4px;}
.m,a.m:link{COLOR:#666666;font-size:100%;}
#ft{clear:both;line-height:20px;background:#E6E6E6;text-align:center}
#ft,#ft *{color:#77C;font-size:12px;font-family:Arial}
#ft span{color:#666}
#usrbar{padding-right:10px;line-height:19px;font-size:12px;font-family:Arial;text-align:right;white-space:nowrap;margin-bottom:3px !important;margin-bottom:10px;}
.kw {font-family:Verdana;font-size:18px;}
.sb {height:2em;width:5.6em;font-size:14px;}
#b {width:600px;height:30px;padding-top:4px;color:#77c;font-size:12px;font-family:Arial}
#km {font-size:14px;height:50px;}
#l {font-size:14px;font-family:arial;width:600px;text-align:left;margin-bottom:5px}
img{border:0}

</style>

<title><?php
$keyword = htmlspecialchars($_GET['keyword']);
if ($keyword != "") {
echo "网页教学网站内搜索_" . $keyword . "——Powered By WEBJX.COM";
?></title>
<?php

} else {
?>
百度首页
</title>
</head>
<body>
<br /></br />
</br />
</br />
</br />
<center><a href="/index.html" target="_blank"> <img
src="images/baidu_img.gif" alt="网页教学网站内搜索" width="189" height="75"
border="0" /></a><br />
<p id="nv"><a href="http://news.baidu.com">新&nbsp;闻</a> <b>网&nbsp;页</b>
<a href="http://tieba.baidu.com">贴&nbsp;吧</a> <a
href="http://zhidao.baidu.com">知&nbsp;道</a> <a
href="http://mp3.baidu.com">MP3</a> <a href="http://image.baidu.com">图&nbsp;片</a>
<a href="http://video.baidu.com">视&nbsp;频</a> <a
href="http://map.baidu.com">地&nbsp;图</a></p>
<table width="600" border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="92"></td>
<td height="62">

<form action="/search.php" method="get" name="search_form"
target="_self" id="f"><input type="text" name="keyword"
class="kw" size="32" maxlength="100" /> <input type="hidden"
name="page" value="1" /> <input name="submit" type="submit"
class="sb" value="站内搜索" /> <input type="hidden" name="writekeywords"
value="yes" /> <br />
<br />
</form>
</td>
<td width="100" align="left"><a href="/others/search_help.html"
target="_self" style="font-size:12px">帮助</a><br />
</td>
</tr>
</table>
<br />
<p style="height:30px;"><a target=_top
href=javascript:window.external.AddFavorite(
'http://www.webjx.com','网页教学网') style="font-size:12px">把网页教学网加入收藏</a></p>
<p style="height:14px;font-size:12px;"><a
href="/others/about_cn.html" target="_blank">关于网页教学网</a> | <a
href="/others/about_en.html" target="_blank" style="font-size:12px">About
Webjx.com</a></p>
<p id="b" style="font-size:12px">&copy;2007 webjx.com <a
href="http://www.baidu.com/duty" /></a></a> <a
href="http://www.miibeian.gov.cn" target="_blank">冀ICP备05002422号</a> <a
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001092500412">
<img src="http://gimg.baidu.com/img/gs.gif" /></a></p>
</center>
</body>
</html>
<?php

exit (0);//不搜索时显示首页 并退出
}
?>
</head>
<body>
<table width="100%" height="54" align="center" cellpadding="0"
cellspacing="0">
<form action="/search.php" method="get" name="search_form"
target="_self">
<tr valign="middle">
<td width="100%" valign="top" style="padding-left:8px;width:137px;"
nowrap="nowrap"><a href="/index.html"><img
src="images/baidu_img.gif" border="0" alt="到网页教学网首页" /></a></td>
<td>&nbsp;</td>
<td width="100%" valign="top">
<div class="Tit">&nbsp;&nbsp;</div>
<table cellspacing="0" cellpadding="0">
<tr>
<td>
<p id="nv"><a href="http://news.baidu.com">新&nbsp;闻</a> <b>网&nbsp;页</b>
<a href="http://tieba.baidu.com">贴&nbsp;吧</a> <a
href="http://zhidao.baidu.com">知&nbsp;道</a> <a
href="http://mp3.baidu.com">MP3</a> <a
href="http://image.baidu.com">图&nbsp;片</a> <a
href="http://video.baidu.com">视&nbsp;频</a> <a
href="http://map.baidu.com">地&nbsp;图</a></p>
</td>
</tr>
<tr>
<td valign="top" nowrap="nowrap">
<input name="keyword" type="text" size="39" maxlength="20" value="<?PHP echo $keyword;?>"/>
<input type="hidden" name="writekeywords" value="yes" />
<input name="submit" type="submit" style="padding-top:2px;" value="搜索本站" />
<input type="hidden" name="page" value="1" />
</td>
<td valign="middle" nowrap="nowrap">
<a href="/others/search_help.html" target="_blank" style="font-size:12px">搜索帮助</a>
</td>
</tr>
</table>
</td>
<td></td>
</tr>
</form>
</table>
<hr />
<table width="100%" border="0" align="center" cellpadding="0"
cellspacing="0" class="bi">
<tr>
<td nowrap style="FONT-SIZE:9pt;LINE-HEIGHT:18px;">&nbsp;&nbsp;&nbsp;
<a target="_top" href="javascript:window.external.AddFavorite('http://www.webjx.com','网页教学网')">把网页教学网设加入收藏</a>.
</a><span style="font-size:12px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注意:此为本站搜索引擎,并非<a href="http://www.google.cn/" target="_blank">Google</a>或者<a
href="http://www.baidu.com/" target="_blank">百度</a>数据。</span>
</td>
<?php
$page = $_GET['page'];
$allpage = $_GET['allpage'];
$cnt = $_GET['cnt'];
$yesno_1 = 0;
//echo "page:".$page." all:".$allpage." cnt:".$cnt;
if ($_GET['writekeywords'] == "yes") {
require ("php_admin/common.inc.php");
$query = " SELECT * FROM nan_keyword WHERE word='" . $keyword . "'";
require ("php_admin/admin_conn_1.php"); //搜索关键字
while ($row = mysql_fetch_array($result)) {
$yesno_1 = $row[3];
}
if (!$yesno_1) //if count(*) is NULL
{
require ("php_admin/common.inc.php");
$query = "INSERT INTO nan_keyword(id,word,num,date) VALUES (NULL,'" . $keyword . "',1,'" . date("Y-m-d", time()) . "')";
require ("php_admin/admin_conn_1.php");
if (!$query) {
//echo "插入新搜索关键词失败!";
} else {
//echo "插入新搜索关键词成功!";
}
$yesno_1 = 0;
} else //count(*)is not NULL
{
$num = $yesno_1 +1;
require ("php_admin/common.inc.php");
$query = "UPDATE nan_keyword SET num=" . $num . ",date='" . date("Y-m-d", time()) . "'WHERE word='" . $keyword . "'";
require ("php_admin/admin_conn_1.php");
if (!$query) {
//echo "更新搜索关键词失败!";
} else {
//echo "更新搜索关键词成功!";
}
}
require ("php_admin/common.inc.php");
$query = " SELECT count(*) FROM nan_article WHERE title LIKE '%" . $keyword . "%' OR about LIKE '%" . $keyword . "%' OR content LIKE '%" . $keyword . "%'";
require ("php_admin/admin_conn_1.php");
if ($row = mysql_fetch_array($result)) /*取得数据表的所有符合项*/
$cnt = $row[0];
if ($cnt != 0) {
$allpage = ceil($cnt / 10);
} else {
$allpage = 0;
}
}
?>
<td align="right" nowrap style="FONT-SIZE:9pt;LINE-HEIGHT:18px;">搜索一下,找到相关网页<?php echo $cnt; ?>篇&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
<?PHP

if ($allpage == 0) {
?>
<div style="margin:0 0 0 15px;font-size:14px;line-height:20px;">
抱歉,没有找到与“<?PHP echo $keyword; ?>”相关的网页。 <br />
<br />
本站建议您:
<div style="margin-top:0px;margin-left:15px;">
<li>看看输入的文字是否有误</li>
<li>去掉可能不必要的字词,如“的”、“什么”等</li>
<li>阅读<a href="/search/noresult.html" target="_blank">帮助</a></li>
</div>
</div>
<?PHP

} else {
require ("php_admin/common.inc.php");
$query = " SELECT * FROM nan_article WHERE title LIKE '%" . $keyword . "%' OR about LIKE '%" . $keyword . "%' OR content LIKE '%" . $keyword . "%' order by id DESC LIMIT " . (10 * ($page -1)) . "," . (10 * $page);
require ("php_admin/admin_conn_1.php");


while ($row = mysql_fetch_array($result)) {
//将关键字标记出来
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class=f style="FONT-SIZE:9pt;LINE-HEIGHT:18px;">
<font color="#C60A00"></font>
<a href="<?=$row[2]?>" target="_blank" title="<?=$row[2]?>">
<font size="3" color="#261cdc">
<?php

$r11 = strip_tags($row[1]);
$title = str_replace($keyword ,"<font color=red>".$keyword."</font>",$r11);
if (strlen($r11) > 80) {
$sc_t = substr($title, 0, 80);
echo $sc_t . "...";
} else {
echo $title;
}
?></font></a><br>
<font size=-1> <?
$desc = str_replace($keyword ,"<font color=red>".$keyword."</font>",$row[4]);
$r31 = strip_tags($desc,"<font>");
if (strlen($r31) > 391) {
$b = substr($r31, 0, 291);
echo $b . "..." . "<br>";
} else {
echo $r31 . "<br>";
}
?></font> <font color=#008000> <?PHP echo $row[2];?> &nbsp;
<?PHP echo $sc_fl=substr($row[6],0,17);?> </font> <?php

switch ($row[5]) {
case "新手入门" :
?><a href="/newer.html" target="_blank" class="m">新手入门常见问题</a> <?PHP

break;
case "PHP基础" :
?> <a href="/base.html" target="_blank" class="m">PHP基础</a> <?PHP

break;
case "PHP进阶" :
?><a href="/newer.html" target="_blank" class="m">PHP进阶</a> <?PHP

break;
case "数据库" :
?> <a href="/base.html" target="_blank" class="m">数据库操作</a> <?PHP

break;
case "PHP源码" :
?><a href="/newer.html" target="_blank" class="m">PHP源码</a> <?PHP

break;
}
?> </font></td>
</tr>
</table>
<br>
<?PHP

} //搜索正文结束
if ($allpage != 1) {
?>
<div class="p"><?PHP
echo $keyword."<br>";
if ($page != 1)
echo "<a href=\"search.php?page=" .
($page -1) . "&cnt=" . $cnt . "&allpage=" . $allpage . "&keyword=" . $keyword ."\" target=_self>上一页</a>";
for ($i = 0; $i < $allpage; $i++) {
if (($i +1) != $page)
echo " <a href=\"search.php?page=" . ($i +1) . "&cnt=" . $cnt . "&allpage=" . $allpage . "&keyword=" . $keyword . "\" target=_self>[" . ($i +1) . "]</a> ";
else
echo " [" . ($i +1) . "] ";
}
if ($allpage != $page)
echo "<a href=\"search.php?page=" .
($page +1) . "&cnt=" . $cnt . "&allpage=" . $allpage . "&keyword=" . $keyword . "\" target=_self>下一页</a>";
}
?></div>
<?PHP

}
?>
<table cellpadding="0" cellspacing="0"
style="margin-left:18px;height:60px;">
<form action="/search.php" method="get" target="_self">
<tr valign="middle">
<td nowrap style="FONT-SIZE:9pt;LINE-HEIGHT:18px;"><input
name="keyword" type="text" size="35" value="<?PHP echo
$keyword;?>"maxlength="20" /> <input type="hidden"
name="writekeywords" value="yes" /> <input name="submit"
type="submit" style="padding-top:2px;" value="搜索本站" /> <input
type="hidden" name="page" value="1" /></td>
</tr>
</form>
</table>
<div id="ft">&copy;2007 网页教学网 <span>此内容系网页教学网根据您的指令自动搜索的结果</span></div>
</body>
</html>

posted on 2012-02-16 15:24  曾经沧海 云淡风轻  阅读(1522)  评论(0编辑  收藏  举报