日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

如何使ASP實(shí)現(xiàn)搜索關(guān)鍵字高亮(2)_ASP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:解析ASP檢查網(wǎng)站鏈接是否正常的函數(shù)
% FunctionurlChk(sUrl) onerrorresumenext SetxmlHttp=Server.CreateObject(Microsoft.XMLHTTP) xmlHttp.openGET,sUrl,false xmlHttp.send ifxmlHttp.Status200then urlChk=false else urlChk=true endif EndFunction sUrl=http://www.code-123.com ifu

    在上面的代碼中,有一個(gè)自定義函數(shù) AutoKey ,該函數(shù)是實(shí)現(xiàn)智能搜索的核心所在。代碼如下:
 <%
Function AutoKey(strKey)
CONST lngSubKey=2
Dim lngLenKey, strNew1, strNew2, i, strSubKey

’檢測字符串的合法性,若不合法則轉(zhuǎn)到出錯(cuò)頁。出錯(cuò)頁你可以根據(jù)需要進(jìn)行設(shè)定。

if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,"")<>0 or InStr(strKey," ")<>0 or InStr(strKey," ")<>0 or InStr(strKey,"")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then
Response.Redirect "error.htm"
End If
lngLenKey=Len(strKey)
Select Case lngLenKey
Case 0 ’若為空串,轉(zhuǎn)到出錯(cuò)頁
Response.Redirect "error.htm"
Case 1 ’若長度為1,則不設(shè)任何值
strNew1=""
strNew2=""
’Case Else 若長度大于1,則從字符串首字符開始,循環(huán)取長度為2的子字符串作為查詢條件
For i=1 To lngLenKey-(lngSubKey-1)
strSubKey=Mid(strKey,i,lngSubKey)
strNew1=strNew1 & " or U_Name like %" & strSubKey & "%"
strNew2=strNew2 & " or U_Info like %" & strSubKey & "%"
Next
End Select
’得到完整的SQL語句

AutoKey="Select * from T_Sample where U_Name like %" & strKey & "% or U_Info like %" & strKey & "%" & strNew1 & strNew2
End Function
%>

    要實(shí)現(xiàn)智能搜索,其核心就是將搜索關(guān)鍵字進(jìn)行自動(dòng)分組。在此處,我們使用了循環(huán)取長度為2的子串的方法。為什么不將子串長度定為1、3、4或其他呢?這是因?yàn)槿糇哟L度小于2即為1時(shí),會(huì)失去將關(guān)鍵字分組的功能,而若子串長度大于2,則會(huì)丟失一些詞組。大家可以將 CONST lngSubKey=2改為其他數(shù)字試一試,孰優(yōu)孰劣自見分曉。 
    最后,別忘了將數(shù)據(jù)連接關(guān)閉,以釋放資源。
 <%
CNN.Close
Set CNN=Nothing
%>

    至此,這個(gè)智能搜索引擎已經(jīng)完成了。你還可以將其繼續(xù)完善,比如添加分頁、突出顯示等功能。

分享:ASP教程之a(chǎn)sp制作常見flash新聞圖片輪換代碼
這是一個(gè)正常的網(wǎng)頁文件 html head metahttp-equiv=Content-Typecontent=text/html;charset=gb2312/ title 新聞圖片輪換 /title /head body !--#Includefile=diaoyong.asp-- /body /html 任何網(wǎng)頁只要調(diào)用下面這個(gè)文件(diaoyong.asp)就可以了,所用f

共2頁上一頁12下一頁
來源:模板無憂//所屬分類:ASP教程/更新時(shí)間:2010-01-09
相關(guān)ASP教程