欢迎光临
我们一直在努力

文本搜索

建站超值云服务器,限时71元/月

<%

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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 文本搜索
分享到: 更多 (0)