<?
// +---------------------------------------------------+
// |实现搜索功能的文档
// |执行顺序:
// |首先提出目录中的文件名并把文件名导入数据库中
// |然后-提交处理部分
// | 查询出后高亮显示;
// +---------------------------------------------------+// +-----------------开始---------提出目录中的文件名并把文件名导入数据库中---------+
$db=@mysql_connect("localhost","*****","******");
$sel=mysql_select_db("******");
$dbname="****";
$pp=mysql_query("DELETE FROM search");// +-----------------------------------+
$FileCount=0;//文件个数
function FCount($Path)
{
global $FileCount,$DirectoryCount;
$Handle = opendir($Path); while($File = readdir($Handle))
{ if(filetype($Path.$File) != 'dir')
{
$_name=$Path.$File;
$filename=$File;
$fArr=explode(".",$filename);
$tArr=explode(":",$fArr[0]);
for($i=0;$i<count($tArr);$i++)$ret.=chr(hexdec($tArr[$i]));
// +-----------------------------------+
$db=@mysql_connect("localhost","****","********");
$sel=mysql_select_db("******");
$dbname="******";
$sql="insert into search values(".$FileCount.","."\"".$ret."\"".",\"".$_name."\"".");";
$result = mysql_query($sql);//sql语句执行
// +-----------------------------------+
$ret="";
$FileCount++;
}
}
closedir($Handle);
}
FCount('./savedocument/');//当前目录下的savedocument下的所有文件
// +-----------------结束---------提出目录中的文件名并把文件名导入数据库中---------+?><?// +---------提交显示界面开始-----------------------+?>
<body id=body11 bgcolor='#FFFFFF' text='#000000' onload="inputform.aa.focus();">
<table width='100%' border='0' cellspacing='0' cellpadding='0' height='224'>
<tr>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='102' bgcolor='#0033FF'><font color='#99CC66' face='Geneva, Arial, Helvetica, san-serif' size='5'><b></b></font></td>
<td width='670' bgcolor='#0033FF'><font color='#99CC66' face='Geneva, Arial, Helvetica, san-serif' size='5'><b><font color='#00FFCC'>文章代码搜索</font></b></font></td>
<td width='1'> </td>
<td width='2'> </td>
</tr>
<tr>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='400' bgcolor='#FFFFFF' valign='bottom'>
<div align='right'><font color='#99CC66' face='Geneva, Arial, Helvetica, san-serif' size='5'><b></b></font></div>
</td>
<td width='670'>请输入搜索关键字:
<form id=inputform method=post action="<? echo $PHP_SELF;?>?act=1">
<input id=aa type='text' title="在此输入查询内容!" name='str'>
<input type='submit' name='Submit' value='开始搜索'>
</form>
</td>
<td width='1'> </td>
<td width='2'> </td>
</tr>
<tr>
<td height='0' width='1'> </td>
<td height='0' width='1'> </td>
<td height='0' colspan='2'> </td>
<td height='0' width='102'> </td>
<td height='12' width='670'>ok.................</td>
<td height='100' width='1'> </td>
<td height='100' width='2'> </td>
</tr>
<tr>
<td height='24' width='1'> </td>
<td height='24' width='1'> </td>
<td height='24' width='1'> </td>
<td height='24' width='1'> </td>
<td height='24' width='102'> </td>
<td height='24' width='670'> </td>
<td height='24' width='1'> </td>
<td height='24' width='2'> </td>
</tr>
</table>
<?// +--------提交显示界面结束-----------------------+?><?// +------提交处理部分开始-----------------------------+?>
<?
if ($str!="") {
$_pp=@mysql_connect("localhost","******","**************");
$dbname="******";
$_pp1=mysql_select_db($dbname);
$sql="select name from search where name like '%".$str."%';";
$result=mysql_query($sql);
$_pp2=0;
while($record=@mysql_fetch_row($result)){
$_pp2++;
$_record=$record[0];
// +--找回源路径---------------------------------+
$sql="select name1 from search where name="."\"".$_record."\";";
//echo $sql;
$_result=mysql_query($sql);
$_result1=@mysql_fetch_row($_result);
// +-----------------------------------+
$record[0]=str_replace($str,"<font color='red'>".$str."</font>",$record[0]);
$string.=$_pp2."、<a href=$_result1[0]>".$record[0]."</a><br>";
}
echo "您查询的关键字为:<b>".$str."</b> 一共找到了".$_pp2."项结果:";
echo"<HR>";
}
?>
<div id="display_area" width=100 height=100><?echo $string?><br><hr><br>成功天地间,伴君行千里!</div>
</body>
</html>
仅能搜索一个目录中的文件名且是中文的(一个例子。php),有许多不足之处,仅作参考。
// +---------------------------------------------------+
// |实现搜索功能的文档
// |执行顺序:
// |首先提出目录中的文件名并把文件名导入数据库中
// |然后-提交处理部分
// | 查询出后高亮显示;
// +---------------------------------------------------+// +-----------------开始---------提出目录中的文件名并把文件名导入数据库中---------+
$db=@mysql_connect("localhost","*****","******");
$sel=mysql_select_db("******");
$dbname="****";
$pp=mysql_query("DELETE FROM search");// +-----------------------------------+
$FileCount=0;//文件个数
function FCount($Path)
{
global $FileCount,$DirectoryCount;
$Handle = opendir($Path); while($File = readdir($Handle))
{ if(filetype($Path.$File) != 'dir')
{
$_name=$Path.$File;
$filename=$File;
$fArr=explode(".",$filename);
$tArr=explode(":",$fArr[0]);
for($i=0;$i<count($tArr);$i++)$ret.=chr(hexdec($tArr[$i]));
// +-----------------------------------+
$db=@mysql_connect("localhost","****","********");
$sel=mysql_select_db("******");
$dbname="******";
$sql="insert into search values(".$FileCount.","."\"".$ret."\"".",\"".$_name."\"".");";
$result = mysql_query($sql);//sql语句执行
// +-----------------------------------+
$ret="";
$FileCount++;
}
}
closedir($Handle);
}
FCount('./savedocument/');//当前目录下的savedocument下的所有文件
// +-----------------结束---------提出目录中的文件名并把文件名导入数据库中---------+?><?// +---------提交显示界面开始-----------------------+?>
<body id=body11 bgcolor='#FFFFFF' text='#000000' onload="inputform.aa.focus();">
<table width='100%' border='0' cellspacing='0' cellpadding='0' height='224'>
<tr>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='102' bgcolor='#0033FF'><font color='#99CC66' face='Geneva, Arial, Helvetica, san-serif' size='5'><b></b></font></td>
<td width='670' bgcolor='#0033FF'><font color='#99CC66' face='Geneva, Arial, Helvetica, san-serif' size='5'><b><font color='#00FFCC'>文章代码搜索</font></b></font></td>
<td width='1'> </td>
<td width='2'> </td>
</tr>
<tr>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='1'> </td>
<td width='400' bgcolor='#FFFFFF' valign='bottom'>
<div align='right'><font color='#99CC66' face='Geneva, Arial, Helvetica, san-serif' size='5'><b></b></font></div>
</td>
<td width='670'>请输入搜索关键字:
<form id=inputform method=post action="<? echo $PHP_SELF;?>?act=1">
<input id=aa type='text' title="在此输入查询内容!" name='str'>
<input type='submit' name='Submit' value='开始搜索'>
</form>
</td>
<td width='1'> </td>
<td width='2'> </td>
</tr>
<tr>
<td height='0' width='1'> </td>
<td height='0' width='1'> </td>
<td height='0' colspan='2'> </td>
<td height='0' width='102'> </td>
<td height='12' width='670'>ok.................</td>
<td height='100' width='1'> </td>
<td height='100' width='2'> </td>
</tr>
<tr>
<td height='24' width='1'> </td>
<td height='24' width='1'> </td>
<td height='24' width='1'> </td>
<td height='24' width='1'> </td>
<td height='24' width='102'> </td>
<td height='24' width='670'> </td>
<td height='24' width='1'> </td>
<td height='24' width='2'> </td>
</tr>
</table>
<?// +--------提交显示界面结束-----------------------+?><?// +------提交处理部分开始-----------------------------+?>
<?
if ($str!="") {
$_pp=@mysql_connect("localhost","******","**************");
$dbname="******";
$_pp1=mysql_select_db($dbname);
$sql="select name from search where name like '%".$str."%';";
$result=mysql_query($sql);
$_pp2=0;
while($record=@mysql_fetch_row($result)){
$_pp2++;
$_record=$record[0];
// +--找回源路径---------------------------------+
$sql="select name1 from search where name="."\"".$_record."\";";
//echo $sql;
$_result=mysql_query($sql);
$_result1=@mysql_fetch_row($_result);
// +-----------------------------------+
$record[0]=str_replace($str,"<font color='red'>".$str."</font>",$record[0]);
$string.=$_pp2."、<a href=$_result1[0]>".$record[0]."</a><br>";
}
echo "您查询的关键字为:<b>".$str."</b> 一共找到了".$_pp2."项结果:";
echo"<HR>";
}
?>
<div id="display_area" width=100 height=100><?echo $string?><br><hr><br>成功天地间,伴君行千里!</div>
</body>
</html>
仅能搜索一个目录中的文件名且是中文的(一个例子。php),有许多不足之处,仅作参考。
<?
$FileCount = 0; //文件个数
$DirectoryCount = 0; //目录个数
function FCount($Path)
{
global $FileCount,$DirectoryCount;
$Handle = opendir($Path);
while($File = readdir($Handle))
{
if(filetype($Path.$File) != 'dir')
{
echo "----文件名----$File<br>";
$FileCount++;
}
if($File !='.' && $File !='..' && filetype($Path.$File)=='dir')
{
echo "目录名----$File<br>";
$DirectoryCount++;
FCount($Path."$File/");
}
}
closedir($Handle);
}FCount('./hyforum_code/');
echo "<br>请您注意脚本程序30秒钟超时警告<br><br>目录个数……………………$DirectoryCount<br>----文件个数……………………$FileCount<br>";
?>