需要一个集合很多功能的搜索条,所以就做了这个。。
呵,也许你会觉得方法很笨,但的确好用,其实可以用更简单的方法的,不用这么多的搜索表单数据,但这样更形象一点,其实是牺牲了性能,做的漂亮一点。。
//万能搜索条
//支持模板,页面无刷新
// 作者:天地小子 [email protected]
//转载或修改请保留原版权,谢谢
//此页面用于生成搜索表单数据,也可以将期做成函数或类什么的。
<?php
//三个参数:
/*
t1 选择搜索引擎 DEFAULT BAIDU
t2 选择大分类 DEFAULT WEB网页搜索
mb 选择模板 DEFAULT 1
*/
if ($_GET[t1]=="baidu" || empty($_GET[t1]))
$ttype="baidu";
elseif($_GET[t1]=="google")
$ttype="google";
elseif($_GET[t1]=="yisou")
$ttype="yisou";
else
$ttype="baidu";
if (empty($_GET[t2]))
$t2type=="web";
else
$t2type=$_GET[t2];
if (empty($_GET[mb]))
$tmb=2;
else
$tmb=$_GET[mb];
?>
<?php
//定义模板,其中不能有双引号或是换行符
//根据URL参数MB来决定采用哪个模板来显示表单
//模板中有四个变量
/*
{forms} 代表HTML表单中的<form>标签
{body1} 代表搜索框
{body2} 代表搜索小分类,如音乐中的 WMV WAV MP3等等
{fenlei} 代表搜索的大分类 如: 网页 音乐 图片 等等
*/
$smb[1]='<table width=533 border=0 cellspacing=0>{forms}<tr><td width=443><div align=center>{body1}</div>{body2}</td><td width=86 align=center valign=middle><table width=100% height=35 border=0 align=center cellspacing=0 bordercolor=#CCCCCC><tr><td>{fenlei}</td></tr></table></td></tr></form></table>';
$smb[2]='<table width=582 border=0 cellspacing=0>{forms}<tr><td width=580>{body1}{fenlei}<br>{body2}</td></tr></table>';
?>
<?php
if ($ttype=="baidu")/////////////////////////////////////////////baidu
{
?>
<?php
//产生大分类下拉框,
$fenleiselect='<select name=baiduselect onChange=javascript:getdataw(\'baidu\',this.value);><option value=web ';
if ($t2type=="web") $fenleiselect.=" selected";
$fenleiselect.='>网页</option><option value=news';
if ($t2type=="news") $fenleiselect.=" selected";
$fenleiselect.='>新闻</option><option value=music';
if ($t2type=="music") $fenleiselect.=" selected";
$fenleiselect.='>音乐</option><option value=pic';
if ($t2type=="pic") $fenleiselect.=" selected";
$fenleiselect.='>图片</option><option value=tb';
if ($t2type=="tb") $fenleiselect.=" selected";
$fenleiselect.='>贴吧</option><option value=site';
if ($t2type=="site") $fenleiselect.=" selected";
$fenleiselect.='>网站</option></select>';
switch ($t2type){
case "web":
$smb[$tmb]=str_replace('{forms}','<form name=f action=http://www.baidu.com/baidu target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input type=text name=wd class=ff size=35 maxlength=100><input type=hidden name=cl value=3><input type=submit value=百度搜索>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
case "news":
$smb[$tmb]=str_replace('{forms}','<FORM action=http://news.baidu.com/ns target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<INPUT class=formfont size=35 name=word><INPUT type=submit value=全文 name=content><INPUT type=submit value=标题 name=title>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','<input type=hidden value=2 name=cl><input type=hidden value=0 name=ct><input type=hidden value=20 name=rn><input type=hidden value=news name=tn>',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
case "tb":
//如果这个搜索表单需要JS代码配合,则全部在此输出,不要带<script>标签,只有这里才能有回车,其它地方如果有回车会出错。
echo 'function gowhere(formname)
{
if (formname.myselectvalue.value == "1")
{
if(formname.word.value=="" || formname.word.value==null){
formname.tn.value = "baiduKeywordSearch";
formname.ct.value = "318767104";
formname.kw.value = "";
formname.rn.value = "50";
formname.lm.value = "0";
formname.pn.value = "0";
}
else {
formname.tn.value = "";
formname.ct.value = "";
formname.rn.value = "";
formname.lm.value = "";
formname.pn.value = "";
formname.kw.value=formname.word.value
}
}
if (formname.myselectvalue.value == "0")
{
formname.tn.value = "baiduPostSearch";
formname.ct.value = "352321536";
formname.lm.value = "65536";
formname.rn.value = "10";
formname.kw.value="";
}
if (formname.myselectvalue.value == "2")
{
formname.tn.value = "baiduPostSearch";
formname.ct.value = "352321536";
formname.lm.value = "65541";
formname.rn.value = "10";
formname.kw.value="";
}
if (formname.word.value == "")
{
alert("请输入搜索关键词!");
formname.word.focus();
return (false);
}
formname.action = url;
return true;
}
';
//用从搜索引擎网页下的源代码中关于搜索表单的源代码更新模板
$smb[$tmb]=str_replace('{forms}','<form name=f1 action=http://post.baidu.com/f onsubmit=\"return gowhere(this)\" target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input type=hidden name=ct value=318767104><input type=hidden name=tn value=baiduKeywordSearch><input type=hidden name=rn value=50><input type=hidden name=pn value=0><input type=hidden name=lm><input type=hidden name=kw><input type=hidden name=rs2 value=0><input name=myselectvalue type=hidden value=1><input type=text name=word class=ff size=35 maxlength=256><input type=submit value=百度搜索>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','<input type=radio name=tb checked onclick=\"document.f1.myselectvalue.value=1;document.f1.rs2.value=0\">进入贴吧 <input type=radio name=tb onclick=\"document.f1.myselectvalue.value=0;document.f1.rs2.value=1\">贴吧搜索 <input type=radio name=tb onclick=\"document.f1.myselectvalue.value=2;document.f1.rs2.value=2\">按作者检索',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
//此处的searchtoolbar 是显示页中将要显示搜索条的<div>标签的ID
break;
case "music":
echo 'function syn(form)
{
if (form.lm[0].checked)
{
form.rn.value="10";
form.tn.value="baidump3lyric";
form.ct.value="150994944";}
else {
if(form.lm[6].checked) {
form.tn.value="baidump3ring"; form.ct.value="285212672";}
else { form.tn.value="baidump3";form.ct.value="134217728";form.rn.value="";}
}
}';
$smb[$tmb]=str_replace('{forms}','<form name=f1 action=http://mp3.baidu.com/m onSubmit=\"syn(this)\" target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input type=hidden name=rn><input type=hidden name=tn value=baidump3><input type=hidden name=ct value=134217728><input type=text name=word class=ff size=35><input type=submit value=百度搜索 name=submit>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','<input name=lm type=radio value=-1>歌词 <input name=lm type=radio checked value=-1>全部音乐 <input name=lm type=radio value=0>mp3 <input name=lm type=radio value=1>rm <input name=lm type=radio value=2>wma <input name=lm type=radio value=6>flash <input name = lm type=radio value=-1> 铃声 ',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
case "pic":
echo 'function gg(formname){
var url;
if (formname.s.value=="1"){
url="http://image.baidu.com/i";
document.f1.tn.value="baiduimage";
document.f1.ct.value="201326592";
document.f1.cl.value="2";
}
else {
if (formname.s.value=="2"){
url="http://imgnews.baidu.com/i";
document.f1.tn.value="baiduimagenews";
document.f1.ct.value="419430400";
document.f1.z.value="0";
document.f1.cl.value="3";
}
}
formname.action = url;
return true;
}';
$smb[$tmb]=str_replace('{forms}','<form name=f1 action=http://image.baidu.com/i onSubmit=\"return gg(this)\" target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input name=z type=hidden><input name=s type=hidden value=1><input name=ct type=hidden value=201326592><input name=cl type=hidden value=2><input name=lm type=hidden value=-1><input name=tn type=hidden value=baiduimage><input type=text name=word size=35 class=ff><input type=submit value=百度搜索>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','<input type=radio name=pic checked value=1 onclick=javascript:this.form.s.value=1;>图片 <input type=radio name=pic value=2 onclick=javascript:this.form.s.value=2;>新闻图片',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
case "site":
$smb[$tmb]=str_replace('{forms}','<form action=http://www.baidu.com/baidu method=get name=query1 target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input name=tn type=hidden value=baidusite><input class=formfont type=text name=word size=35><input type=submit value=百度搜索 name=submit>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
}
exit(0);
?>
<?php
}
elseif ($ttype=="google")//////////////////////////////////////google
{
?>
<?php
$smb[$tmb]=str_replace('{forms}','<FORM method=GET action=http://www.google.com/search name=google target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<INPUT TYPE=text name=q size=35 maxlength=255><INPUT TYPE=hidden name=hl value=zh-CN><INPUT TYPE=hidden name=ie value=GB2312><INPUT TYPE=submit name=btnG value=google搜索>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}','<select name=t2><option selected>网页</option></select>',$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
exit(0);
?>
<?php
}
else ////////////////////////////////////////////////////////////yisou
{
?>
<?php
//分类SELECT
$fenleiselect='<select name=yisouselect onChange=javascript:getdataw(\'yisou\',this.value);><option value=web';
if ($t2type=="web") $fenleiselect.=" selected";
$fenleiselect.='>网页</option><option value=news';
if ($t2type=="news") $fenleiselect.=" selected";
$fenleiselect.='>新闻</option><option value=music';
if ($t2type=="music") $fenleiselect.=" selected";
$fenleiselect.='>音乐</option><option value=pic';
if ($t2type=="pic") $fenleiselect.=" selected";
$fenleiselect.='>图片</option></select>';
switch ($t2type){
case "web":
echo 'function verify_submit(form,name) {
if(name == "music") {
form.action = "http://music.yisou.com/search";
}
form.submit();
return true;
}';
$smb[$tmb]=str_replace('{forms}','<form name=searchweb method=get action=http://www.yisou.com/search target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input name=p type=text id=inpt size=35 maxlength=64><input type=hidden name=source value=yisou_www_hpbox><input type=button id=butn value=一搜搜索 onclick=\"javascript:{return verify_submit(document.searchweb,\'web\');}\" >',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
case "news":
$smb[$tmb]=str_replace('{forms}','<form name=search method=get action=http://news.yisou.com/search target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input name=p type=text id=inpt size=35 maxlength=64><input type=submit name=Submit id=butn value=一搜新闻>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','<input type=radio checked=checked name=title id=all>新闻全文 <input type=radio value=1 name=title id=zh>新闻标题',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
case "music":
echo 'function verify_input(form, name, type) {
if (form.p.value == "") {
alert("请输入搜索关键字!");
return false;
}
if (name == "song") {
if(type == 1){
if(form.mimetype[6].checked == true)
form.action = "searchmms.html";
else
form.action = "search";
}
else
form.action = "search";
}
else {
form.action = "lyric.html";
}
form.submit();
return true;
}';
$smb[$tmb]=str_replace('{forms}','<form name=search method=get action=http://music.yisou.com/search target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input name=p type=text id=inpt size=35 maxlength=64><input type=submit id=butn value=歌曲 onClick=\"javascript:{return verify_input(document.search,\'song\', 1);}\"><input type=submit id=butn value=歌词 onClick=\"javascript:{return verify_input(document.search,\'lyric\', 1);}\">',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','<input type=radio value=all checked name=mimetype id=all>全部<input type=radio value=mp3 name=mimetype id=mp3>mp3<input type=radio value=flash name=mimetype id=flash>flash<input type=radio value=rm name=mimetype id=rm>rm <input type=radio value=wma name=mimetype id=wma>wma<input type=hidden name=source value=yisou_music_hp_search>',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
case "pic":
$smb[$tmb]=str_replace('{forms}','<form name=search method=get action=http://image.yisou.com/search target=_blank>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body1}','<input name=p type=text id=inpt size=35 maxlength=64><input type=submit name=Submit id=butn value=一搜搜索>',$smb[$tmb]);
$smb[$tmb]=str_replace('{body2}','<input type=radio value=chn name=lang checked=checked id=zh>中文图库 <input type=radio value=en name=lang id=all>全球图库 <input type=radio value=trans name=lang id=tran>翻译后搜索全球图库 <input type=hidden name=source value=yisou_img_hp_search>',$smb[$tmb]);
$smb[$tmb]=str_replace('{fenlei}',$fenleiselect,$smb[$tmb]);
echo "document.getElementById(\"searchtoolbar\").innerHTML=\"$smb[$tmb]\";";
break;
}
exit(0);
?>
<?php
}
?>
//此页面是功能使用演示页面--------------------------------------------------------------
<a href="#" onClick="javascript: getdataw('baidu','web');"><img src="image/baidu.gif" alt="百度LOGO图片" width="150" height="45" border="0"></a>
<a href="#" onClick="javascript: getdataw('google','web');"><img src="image/google.gif" alt="GOOGLE LOGO图片" width="150" height="45" border="0"></a>
<a href="#" onClick="javascript: getdataw('yisou','web');"><img src="image/yisou_mp3_hp.gif" alt="一搜 LOGO图片" width=150 height=45 border="0"></a>
<div id="searchtoolbar">这里的内容随便,不填也可</div><script language="javascript" id="instjs"></script>
<script language="javascript">
<!--
function getdataw(t1,t2)
{
//更改这里的各个参数即可以获得相应的表单
phpfilename="search.php?t1=" + t1 + "&t2=" + t2 + "&mb=1";
//alert (phpfilename);
document.getElementById("searchtoolbar").innerHTML="正在获取搜索表单数据,请稍候...";
//如果上一行语句加上的话,必须将这段JS代码放在用于显示表单的<DIV>标签之后
document.getElementById("instjs").src=phpfilename;
}
getdataw("baidu","web");//默认是百度的页面搜索
//-->
</script>
本文地址:http://com.8s8s.com/it/it24025.htm