«
PHP制作的仿百度的站内搜索引擎代码

时间:2008-5-31    作者:Deri    分类: 分享


   <p>  用PHP编写的仿百度的站内搜索引擎代码</p><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br /><style><br />body,td,.p1,.p2,.i{font-family:arial}<br />body{margin:6px 0 0 0;background-color:#fff;color:#000;}<br />table{border:0}<br />a.t:hover{TEXT-DECORATION:underline}<br />.f{line-height:100%;font-size:100%;width:43em;padding-left:15px;word-break:break-all;word-wrap:break-word;}<br />.Tit {height:21px; font-size:14px;}<br />.fB {font-weight:bold;}<br />.i1 {font-size:16px}<br />.bi {background-color:#D9E1F7;height:20px;margin-bottom:12px}<br />.p{padding-left:18px;font-size:14px;word-spacing:4px;}<br />.m,a.m:link{COLOR:#666666;font-size:100%;}<br />#ft{clear:both;line-height:20px;background:#E6E6E6;text-align:center}<br />#ft,#ft *{color:#77C;font-size:12px;font-family:Arial}<br />#ft span{color:#666}<br />#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;}<br />.kw {font-family:Verdana;font-size:18px;}<br />.sb {height:2em;width:5.6em;font-size:14px;}<br />#b {width:600px;height:30px;padding-top:4px;color:#77c;font-size:12px;font-family:Arial}<br />#km {font-size:14px;height:50px;}<br />#l {font-size:14px;font-family:arial;width:600px;text-align:left;margin-bottom:5px}<br />img{border:0}<br /></style><br /><title><br /><?php<br />$keyword=htmlspecialchars($_GET['keyword']);<br />if($keyword!="")<br />{<br />echo "豆豆技术应用站内搜索_".$keyword."――Powered By WEBJX.COM";<br />?> </title><br /><?php<br />}<br />else<br />{?><br /></title><br /></head><br /><body><br /><br /></br /><br /><center><a href="/index.html" target="_blank"><img src="images/php_logo_search_da.gif" alt="豆豆技术应用站内搜索" width="189" height="75" border="0" /></a><br /><br /><br /><br /><br /><br /><br /><br /><table width="600" border="0" cellpadding="0" cellspacing="0"><br /><tr valign="top"><br /><td width="92"></td><br /><td height="62"><form action="/search.php" method="get" name="search_form" target="_self" id="f"><br /><input type="text" name="keyword" class="kw" size="32" maxlength="100"/><br /><input type="hidden" name="page" value="1" /><br /><input name="submit" type="submit" class="sb" value="站内搜索" /><br /><input type="hidden" name="writekeywords" value="yes" /><br /><br /><br /><br /><br /></form></td><br /><td width="100" align="left"><a href="/others/search_help.html" target="_self" style="font-size:12px">帮助</a><br /><br /></td><br /></tr><br /></table><br /><br /><br /><p style="height:30px;"><a target=_top href=javascript:window.external.AddFavorite('http://tech.ddvip.com','豆豆技术应用') style="font-size:12px">把豆豆技术应用加入收藏</a></p><br /><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><br /><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><br /></center></body><br /></html><br /><?PHP<br />exit(0);<br />}<br />?><br /></head><br /><body><br /><table width="100%" height="54" align="center" cellpadding="0" cellspacing="0"><br /><form action="/search.php" method="get" name="search_form" target="_self"><br /><tr valign="middle"><br /><td width="100%" valign="top" style="padding-left:8px;width:137px;" nowrap="nowrap"><a href="/index.html"><img src="/images/php_log_search.gif" border="0" alt="到豆豆技术应用首页" /></a> </td><br /><td>&nbsp;&nbsp;&nbsp;</td><br /><td width="100%" valign="top"><div class="Tit">&nbsp;&nbsp;<br /></div><br /><table cellspacing="0" cellpadding="0"><br /><tr><br /><td valign="top" nowrap="nowrap"><br /><input name="keyword" type="text" size="39" maxlength="20" value="<?PHP echo $keyword;?>"/><br /><input type="hidden" name="writekeywords" value="yes" /><br /><input name="submit" type="submit" style="padding-top:2px;" value="搜索本站"/><br /><input type="hidden" name="page" value="1" /><br />&nbsp;&nbsp;&nbsp;</td><br /><td valign="middle" nowrap="nowrap"><a href="/others/search_help.html" target="_blank" style="font-size:12px">搜索帮助</a></td><br /></tr><br /></table></td><br /><td></td><br /></tr><br /></form><br /></table><br /><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="bi"><br /><tr><br /><td nowrap style="FONT-SIZE:9pt;LINE-HEIGHT:18px;">&nbsp;&nbsp;&nbsp;<a target=_top href=javascript:window.external.AddFavorite('http://tech.ddvip.com','豆豆技术应用')>把豆豆技术应用设加入收藏</a>.<br /></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><br /><?php<br />$page=$_GET['page'];<br />$allpage=$_GET['allpage'];<br />$cnt=$_GET['cnt'];<br />$yesno_1=0;<br />if($_GET['writekeywords']=="yes")<br />{<br />require("php_admin/admin_conn_1.php");<br />$query =" SELECT * FROM nan_keyword WHERE word='".$keyword."'";<br />require("php_admin/admin_conn_2.php");<br />while($row = mysql_fetch_array($result))<br />{<br />$yesno_1=$row[3];<br />}<br />if(!$yesno_1)//if count(*) is NULL<br />{<br />require("php_admin/admin_conn_1.php");<br />$query="INSERT INTO nan_keyword(id,word,num,date) VALUES (NULL,'".$keyword."',1,'".date("Y-m-d",time())."')";<br />require("php_admin/admin_conn_2.php");<br />if(!$query)<br />{<br />//echo "插入新搜索关键词失败!";<br />}<br />else<br />{<br />//echo "插入新搜索关键词成功!";<br />}<br />$yesno_1=0;<br />}<br />else//count(*)is not NULL<br />{<br />$num=$yesno_1+1;<br />require("php_admin/admin_conn_1.php");<br />$query ="UPDATE nan_keyword SET num=".$num.",date='".date("Y-m-d",time())."'WHERE word='".$keyword."'";<br />require("php_admin/admin_conn_2.php");<br />if(!$query)<br />{<br />//echo "更新搜索关键词失败!";<br />}<br />else<br />{<br />//echo "更新搜索关键词成功!";<br />}<br />}<br />require("php_admin/admin_conn_1.php");<br />$query =" SELECT count(*) FROM nan_article WHERE title LIKE '%".$keyword."%' OR about LIKE '%".$keyword."%' OR content LIKE '%".$keyword."%'";<br />require("php_admin/admin_conn_2.php");<br />if($row = mysql_fetch_array($result))/*取得数据表的所有符合项*/<br />$cnt=$row[0];<br />if($cnt!=0)<br />{<br />$allpage=ceil($cnt/10);<br />}<br />else<br />{<br />$allpage=0;<br />}<br />}?><br /><td align="right" nowrap style="FONT-SIZE:9pt;LINE-HEIGHT:18px;">搜索一下,找到相关网页<?php echo $cnt; ?>篇&nbsp;&nbsp;&nbsp;&nbsp;</td><br /></tr><br /></table><br /><?PHP<br />if($allpage==0)<br />{?><br /><div style="margin:0 0 0 15px;font-size:14px;line-height:20px;"><br />抱歉,没有找到与“<?PHP echo $keyword; ?>”相关的网页。 <br /><br /><br /><br />本站建议您:<br /><div style="margin-top:0px;margin-left:15px;"><br /><li>看看输入的文字是否有误 </li><br /><li>去掉可能不必要的字词,如“的”、“什么”等 </li><br /><li>阅读<a href="/search/noresult.html" target="_blank">帮助</a> </li><br /></div><br /></div><?PHP<br />}<br />else<br />{<br />require("php_admin/admin_conn_1.php");<br />$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);<br />require("php_admin/admin_conn_2.php");<br />while($row = mysql_fetch_array($result))<br />{<br />?><br /><table border="0" cellpadding="0" cellspacing="0"><br /><tr><br /><td class=f style="FONT-SIZE:9pt;LINE-HEIGHT:18px;"><br /><font color=#C60A00></font><br /><a href="/html/php<?PHP echo $row[0];?>.html" target="_self" title="<?PHP echo $row[2];?>"><br /><font size="3" color="#261cdc"><br /><?php<br />$r11=strip_tags($row[1]);<br />if(strlen($r11)>69)<br />{<br />$sc_t=substr($r11,0,69);<br />echo $sc_t."...";<br />}<br />else<br />{<br />echo $r11;<br />}<br />?></font></a><br><font size=-1><br /><?<br />$r31=strip_tags($row[3]);<br />if(strlen($r31)>291)<br />{<br />$b=substr($r31,0,291);<br />echo $b."..."."<br>";<br />}<br />else<br />{<br />echo $r31."<br>";<br />}<br />?></font><br /><font color=#008000><br />tech.ddvip.com/html/php<?PHP echo $row[0];?>.html <?PHP echo $sc_fl=substr($row[6],0,17);?><br /></font><br /><?php<br />switch ($row[5])<br />{<br />case "新手入门":<br />?><a href="/newer.html" target="_blank" class="m">新手入门常见问题</a><br /><?PHP break;<br />case "PHP基础":?><br /><a href="/base.html" target="_blank" class="m">PHP基础</a><br /><?PHP break;<br />case "PHP进阶":<br />?><a href="/newer.html" target="_blank" class="m">PHP进阶</a><br /><?PHP break;<br />case "数据库":?><br /><a href="/base.html" target="_blank" class="m">数据库操作</a><br /><?PHP break;<br />case "PHP源码":<br />?><a href="/newer.html" target="_blank" class="m">PHP源码</a><br /><?PHP break;<br />} ?><br /></font></td><br /></tr><br /></table><br><br /><?PHP<br />}//搜索正文结束<br />if($allpage!=1)<br />{?><div class="p"><?PHP<br />if($page!=1)<br />echo"<a href="search.php?page=".($page-1)."&cnt=".$cnt."&allpage=".$allpage."&keyword=".$keyword."" target="_self">上一页</a>";<br />for($i=0;$i<$allpage;$i++)<br />{<br />if(($i+1)!=$page)<br />echo " <a href="search.php?page=".($i+1)."&cnt=".$cnt."&allpage=".$allpage."&keyword=".$keyword."" target="_self">[".($i+1)."]</a> ";<br />else<br />echo " [".($i+1)."] ";<br />}<br />if($allpage!=$page)<br />echo"<a href="search.php?page=".($page+1)."&cnt=".$cnt."&allpage=".$allpage."&keyword=".$keyword."" target="_self">下一页</a>";<br />}?></div><br /><?PHP<br />}<br />?><br /><table cellpadding="0" cellspacing="0" style="margin-left:18px;height:60px;"><br /><form action="/search.php" method="get" target="_self"><tr valign="middle"><br /><td nowrap style="FONT-SIZE:9pt;LINE-HEIGHT:18px;"><br /><input name="keyword" type="text" size="35" value="<?PHP echo $keyword;?>"maxlength="20" /><br /><input type="hidden" name="writekeywords" value="yes" /><br /><input name="submit" type="submit" style="padding-top:2px;" value="搜索本站"/><br /><input type="hidden" name="page" value="1" /><br /></td></tr><br /></form><br /></table><br /><div id="ft">&copy;2007 豆豆技术应用 <span>此内容系豆豆技术应用根据您的指令自动搜索的结果</span></div><br /></body><br /></html></code></p>