例子:文本搜索

2016-01-29 19:38 2 1 收藏

例子:文本搜索,例子:文本搜索

【 tulaoshi.com - ASP 】

       例子:文本搜索
  
  <%
  Head = "搜索"
  SearchString = Request("SearchString")
  count=0
  
  ''把当前目录的实际路径转换为虚拟路径
  Function UnMapPath( Path )
   UnMapPath = Replace(Mid(Path, Len(Server.MapPath("/")) + 1), "", "/")
  End Function
  
  
  Function SearchFile( f, s, title )
   Set fo = fs.OpenTextFile(f)
   content = fo.ReadAll''读全部文本到content
   fo.Close
   SearchFile = InStr(1, content, S, vbTextCompare) > 0 ''从第一个字符开始检查content里面是否有S
   If SearchFile Then''如果有,则提出文件TITLE存入变量
   pos1 = InStr(1, content, "<TITLE>", vbTextCompare)
   pos2 = InStr(1, content, "</TITLE>", vbTextCompare)
   title = ""
   If pos1 > 0 And pos2 > 0 Then''取TITLE标记中间的字符
   title = Mid( content, pos1 + 7, pos2 - pos1 - 7 )
   End If
   End If
  End Function
  
  Function FileLink( f, title )
   vPath = UnMapPath( f.Path )''取路径
   If title = "" Then title = f.Name''做链接
   FileLink = "<A HREF=""" & vPath & """>" & title & "</A>"
   FileLink = "<UL>·" & FileLink & "</UL>"
  End Function
  
  Sub SearchFolder( fd, s )
   found = False
   For each f In fd.Files
   pos = InStrRev(f.Path, "." )
   If pos > 0 Then
   ext = Mid(f.Path, pos + 1 )
   Else
   ext = ""
   End If
   If LCase(ext) = "htm" Then''显示扩展名字为HTM的文件
   If SearchFile( f, s, title ) Then
   Response.Write FileLink(f, title)
   count=count+1
   '' Response.Write cstr(count)
   End If
   End If
   Next
  
   For each sfd In fd.SubFolders
   SearchFolder sfd, s
   Next
  End Sub
  %>
  <html>
  
  <head>
  <meta http-equiv="Content-Type"
  content="text/html; charset=gb_2312-80">
  <meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
  <title><%=Head%></title>
  </head>
  
  <body bgcolor="#FFFFFF">
  
  <h1><%=Head%></h1>
  
  <hr>
  
  <form action="search.asp" method="Get">
   <p>请输入欲搜索的内容: <input type="text"
   size="20" name="SearchString" value="<%=SearchString%>"> <input
   type="submit" value="搜索"> </p>
  </form>
  <%
  Set fs = Server.CreateObject("Scripting.FileSystemObject")
  Set fd = fs.GetFolder( Server.MapPath("/") ) ''设置开始搜索的路径!
  
  If SearchString <> "" Then
   Response.Write "<H2>搜索<font color=red>" & SearchString & "</font>结果如下:</H2><P>"
   SearchFolder fd,SearchString
  End If
  %>
  <hr>
  </body>
  </html>
  
  

 

来源:https://www.tulaoshi.com/n/20160129/1509820.html

延伸阅读
标签: PHP
  现在我们来讲一下reply.php的代码: --------------------------------- //reply.php <?   function check_strlen_long($txt) { $len=strlen($txt); $count=0; for ($i=0;$i<$len;$i++) { if (ord($txt[$i])<128)   { $count=$count+1;}   if (ord($txt[$i])==10 or ord($tx...
标签: PHP
  这一节我将为大家讲述关于guest.txt的建立方法和上传的有关事项. ------- //guest.txt <tr<td<font color=#AB00E1留言内容:</font<br<!--contentzihanonline<!--endcontent <br<font color=#6633FF留言人大名:</font<!--namezihanonline<!--endname <font color=#9900CC主页:</font<a...
标签: PHP
  上一次我们研究了guest.php文件.具体的问题还要求读者朋友自己深入的去实践,而且需要一些工具书来学习,如果您一点php的知识都没有,笔者奉劝您就不要想下看了,笔者没有太多的时间和篇幅去逐句探究一个php文件的用途和意义.好的,接下来我们来作edit.php这个文件. ----------- //edit.php <?    if ($Submit) &nbs...
一个很简单但是最常用的SED例子:UNIX DOS文本格式转换 文本转换第一个实际脚本将 UNIX 风格的文本转换成 DOS/Windows 格式。您可能知道,基于 DOS/Windows的文本文件在每一行末尾有一个 CR(回车)和 LF(换行),而 UNIX 文本只有一个换行。有时可能需要将某些 UNIX 文本移至Windows 系统,该脚本将为您执行必需的格式转换。 $ sed -e 's/$/...
win7搜索文本框不见了应该怎么办?   我们在使用电脑的时候常常不知道什么时候就导致了自己的电脑出现了错误,有时候不小心或者是错误操作就导致我们win7旗舰版电脑系统中的开始菜单里面的搜索文本框不见了,这样就让我们有时候需要用的时候非常的不方便,如何才能解决这个问题需要的朋友可以看看。 恢复搜索文本框操作方法: ...

经验教程

285

收藏

47

精华推荐

AspectSharp例子分析

AspectSharp例子分析

死神是逗比

TabStrip应用例子

TabStrip应用例子

yanmingqia

搜狗搜索怎么拍照搜索

搜狗搜索怎么拍照搜索

开心一族768

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部