PHP-made imitation of Baidu's site search engine code

Source: Internet
Author: User
Tags date count insert php basics php source code require strlen

The following are the referenced contents:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<style>
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 "Web page teaching Site Search _". $keyword. " --powered by webjx.com ";
?> </title>
<?php
}
Else
{?>
</title>
<body>
<br/></br/>
<center><a href= "/index.html" target= "_blank" ></a><br/>
<br/>
<br/>
<br/>
<table width= "border=" 0 "cellpadding=" 0 "cellspacing=" 0 ">
&LT;TR valign= "Top" >
&LT;TD width= "></td>"
&LT;TD height= "><form" action= "/search.php" method= "Get" name= "Search_form" target= "_self" id= "F" >
<input type= "text" name= "keyword" class= "kw" size= "a" maxlength= ""/>
<input type= "hidden" name= "page" value= "1"/>
<input name= "Submit" type= "Submit" class= "SB" value= "Site Search"/>
<input type= "hidden" name= "writekeywords" value= "yes"/>
<br/>
<br/>
</form></td>
&LT;TD width= "align=" "left" ><a href= "/others/search_help.html" target= "_self" style= "font-size:12px" > Help </a><br/>
</td>
</tr>
</table>
<br/>
<p style= "height:30px;" ><a target=_top href=javascript:window.external.addfavorite (' http://www.webjx.com ', ' Web Teaching network ') style= " font-size:12px "> Add Web Teaching Network to Favorites </a></p>
<p style= "HEIGHT:14PX;FONT-SIZE:12PX;" ><a href= "/others/about_cn.html" target= "_blank" > About Web teaching Network </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" >©2007 webjx.com <a href= "Http://www.baidu.com/duty "/></center></body>
? Php
Exit (0);
}
?>
<body>
<table width= "100%" height= "si" align= "center" cellpadding= "0" cellspacing= "0" >
<form action= "/search.php" method= "Get" name= "Search_form" target= "_self" >
<tr valign= "Middle" >
&LT;TD width= "100%" valign= "Top" style= "padding-left:8px;width:137px" nowrap= nowrap "><a" href= "/index.html" ></a> </td>
<td> </td>
&LT;TD width= 100% valign= Top ><div class= >
</div>
<table cellspacing= "0" cellpadding= "0" >
<tr>
&LT;TD valign= "Top" nowrap= "nowrap" >
<input name= "keyword" type= "text" size= "" maxlength= "" value= " PHP echo $keyword;? > "/>
<input type= "hidden" name= "writekeywords" value= "yes"/>
<input name= "Submit" type= "submit" style= padding-top:2px; "value=" Search this site "/>
<input type= "hidden" name= "page" value= "1"/>
</td>
&LT;TD valign= "Middle" nowrap= "nowrap" ><a href= "/others/search_help.html" target= "_blank" style= "font-size" : 12px "> Search Help </a></td>
</tr>
</table></td>
<td></td>
</tr>
</form>
</table>
<table width= "100%" border= "0" align= "center" cellpadding= "0" cellspacing= "0" class= "bi" >
<tr>
&LT;TD nowrap style= "FONT-SIZE:9PT; line-height:18px; " > <a target=_top href=javascript:window.external.addfavorite (' http://www.webjx.com ', ' Web Teaching Network ') > Set up the Web teaching network to add to the collection </a>.
</a><span style= "font-size:12px" > Note: This is the site search engine, not <a href= "http://www.google.cn/" target= "_blank" > google</a> or <a href= "http://www.baidu.com/" target= "_blank" > Baidu </a> data. </span></td>
<?php
$page =$_get[' page '];
$allpage =$_get[' allpage '];
$cnt =$_get[' CNT '];
$yesno _1=0;
if ($_get[' writekeywords ']== "yes")
{
Require ("php_admin/admin_conn_1.php");
$query = "SELECT * from Nan_keyword WHERE word= '". $keyword. "'";
Require ("php_admin/admin_conn_2.php");
while ($row = Mysql_fetch_array ($result))
{
$yesno _1= $row [3];
}
if (! $yesno _1)//if count (*) is NULL
{
Require ("php_admin/admin_conn_1.php");
$query = "INSERT into Nan_keyword (id,word,num,date) VALUES (NULL, '". $keyword. "', 1, '". Date ("Y-m-d", Time ()).
Require ("php_admin/admin_conn_2.php");
if (! $query)
{
echo "Failed to insert new search keyword!" ";
}
Else
{
echo "Insert new search keyword success!" ";
}
$yesno _1=0;
}
Else//count (*) is not NULL
{
$num = $yesno _1+1;
Require ("php_admin/admin_conn_1.php");
$query = "UPDATE nan_keyword SET num=". $num. ", date= '". Date ("Y-m-d", Time ()). "' WHERE word= ' ". $keyword." ' ";
Require ("php_admin/admin_conn_2.php");
if (! $query)
{
echo "Failed to update search keywords!" ";
}
Else
{
echo "UPDATE search keyword success!" ";
}
}
Require ("php_admin/admin_conn_1.php");
$query = "SELECT count (*) from nan_article WHERE title like '% '. $keyword." % ' OR about like '% '. $keyword. " % ' OR content like '% '. $keyword. " %'";
Require ("php_admin/admin_conn_2.php");
if ($row = mysql_fetch_array ($result))/* Get all the entries in the datasheet * * *
$cnt = $row [0];
if ($cnt!=0)
{
$allpage =ceil ($cnt/10);
}
Else
{
$allpage = 0;
}
}?>
&LT;TD align= "right" nowrap style= "FONT-SIZE:9PT; line-height:18px; " > Search, find the relevant web page <?php echo $cnt;?> Chapter </td>
</tr>
</table>
? Php
if ($allpage ==0)
{?>
<div style= "margin:0 0 0 15px;font-size:14px;line-height:20px; " >
Sorry, not found with " PHP echo $keyword?> "related pages. <br/>
<br/>
This site recommends that you:
<div style= "margin-top:0px;margin-left:15px;" >
<li> See if the typed text is incorrect </li>
<li> remove potentially unnecessary words, such as ",", "what" </li>
<li> reading <a href= "/search/noresult.html" target= "_blank" > Help </a> </li>
</div>
</div><? Php
}
Else
{
Require ("php_admin/admin_conn_1.php");
$query = "SELECT * from Nan_article WHERE title is '%". $keyword. " % ' OR about like '% '. $keyword. " % ' OR content like '% '. $keyword. " % ' ORDER by ID DESC LIMIT '. (10* ($page-1)). ",". (10* $page);
Require ("php_admin/admin_conn_2.php");
while ($row = Mysql_fetch_array ($result))
{
?>
<table border= "0" cellpadding= "0" cellspacing= "0" >
<tr>
&LT;TD class=f style= "FONT-SIZE:9PT; line-height:18px; " >
<font color= #C60A00 ></font>
<a href= "/HTML/PHP&LT;? PHP echo $row [0];? >.html "target=" _self "title=" PHP echo $row [2];? > ">
<font size= "3" color= "#261cdc" >
<?php
$r 11=strip_tags ($row [1]);
if (strlen ($r) >69)
{
$SC _t=substr ($r 11,0,69);
echo $sc _t. " ...";
}
Else
{
Echo $r 11;
}
? ></font></a><br><font size=-1>
?
$r 31=strip_tags ($row [3]);
if (strlen ($r) >291)
{
$b =substr ($r 31,0,291);
echo $b. " ..."." <br> ";
}
Else
{
Echo $r 31. " <br> ";
}
?></font>
<font color= #008000 >
www.webjx.com/html/php<? PHP echo $row [0];? >.html;? PHP echo $SC _fl=substr ($row [6],0,17);? >
</font>
<?php
Switch ($row [5])
{
Case "Novice Beginner":
? ><a href= "/newer.html" target= "_blank" class= "M" > Novice Beginners FAQ </a>
? PHP break;
Case "PHP Basics":?>
<a href= "/base.html" target= "_blank" class= "M" >php basic </a>
? PHP break;
Case "PHP Advanced":
? ><a href= "/newer.html" target= "_blank" class= "M" >php advanced </a>
? PHP break;
Case "Database":?>
<a href= "/base.html" target= "_blank" class= "M" > Database Operations </a>
? PHP break;
Case "PHP Source code":
? ><a href= "/newer.html" target= "_blank" class= "M" >php source </a>
? PHP break;
}?>
</font></td>
</tr>
</table><br>
? Php
}//Search Body End
if ($allpage!=1)
{><div class= "P" ><? Php
if ($page!=1)
echo "<a href=" search.php?page= ". ($page-1). " &cnt= ". $cnt." &allpage= ". $allpage." &keyword= ". $keyword." "target=" _self "> Prev </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 "> Next </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" >
&LT;TD nowrap style= "FONT-SIZE:9PT; line-height:18px; " >
<input name= "keyword" type= "text" size= "" value= " PHP echo $keyword;? > "Maxlength="/>
<input type= "hidden" name= "writekeywords" value= "yes"/>
<input name= "Submit" type= "submit" style= padding-top:2px; "value=" Search this site "/>
<input type= "hidden" name= "page" value= "1"/>
</td></tr>
</form>
</table>
<div id= "FT" >©2007 Web teaching network <span> This content Web teaching network automatically search results based on your instructions </span></div>
</body>



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.