实现多个关键词着色的修改
作者:cmscn 日期:2007-02-07
①打开jk_keyes.asp
在%>前面添加:
'#########分割多个关键词##########################
function search_tuwen(b_keyes,strers,kt)
dim ddim,dnum,di,spvar,result,stypes
stypes=trim(request.querystring("sea_type"))
if var_null(b_keyes)="" or var_null(stypes)<>"topic" then
b_keyes=""
call getMatchText(b_keyes,strers,result,true)
search_tuwen=result
exit function
end if
spvar=","
if kt=2 then spvar=" "
b_keyes=replace(b_keyes,"'","")
ddim=split(b_keyes,spvar)
dnum=ubound(ddim)
b_keyes="("&ddim(0)&")"
for di=1 to dnum
b_keyes=b_keyes&"|("&ddim(di)&")"
next
erase ddim
call getMatchText(b_keyes,strers,result,false)
search_tuwen=result
end function
'#######################关键词加色的重点处理####################
sub getMatchText(byref patern,byref str,byref result,isNeedTrunc)
Dim regEx, Match, Matches,found
dim tStr
Set regEx = New RegExp '建立正则表达式。
regEx.Pattern = (patern) '设置模式。
regEx.IgnoreCase = True '设置是否区分字符大小写。
regEx.Global = True '设置全局可用性。
Set Matches = regEx.Execute(str) '执行搜索。
if err.number<>0 then
response.write "错误1:"&err.description
err.clear
exit sub
end if
if matches.count <>0 then
dim startIndex
dim myMatchvalue
startIndex=1
for each match in matches
if (instr(str,match.value)>0) then
if instr(str,match.value)-50 >0 then
startIndex=instr(str,match.value)-50
else
startIndex=1
end if
myMatchvalue=match.value
exit for
end if
next
if isNeedTrunc then
result=(mid(str,startIndex,len(myMatchvalue)+100)) 'strLength
else
result=(str)
end if
for each match in matches
if not(instr(result,"<font color=red><u>"&match.value&"</u></font>")>0) then
result=replace(result,match.value,"<font color=red><u>"&match.value&"</u></font>" )
end if
next
found=true
else
found=false
end if
set regEx=nothing
end sub
②打开forum_search.asp
找到function forum_topic_type里面的joekoe_cms.code_html(t_topic,1,28)修改为:
search_tuwen(keyword,t_topic,2)
=========================================
参数说明:
search_tuwen(b_keyes,strers,kt)关键词设置
search_tuwen(b_keyes,strers,kt)关键词所需内容
search_tuwen(b_keyes,strers,kt)设置模式:
当KT为2是为空格提示关键词,不等于2为","提示关键词
对照下调用的时候,没红色部分就请自己加上!
call forum_topic_type(rs("id"),rs("forum_id"),joekoe_cms.code_html(rs("topic"),1,0),rs("tim"),rs("username"),rs
("re_username"),rs("re_tim"),rs("counter"),rs("re_counter"),rs("istop"),rs("islock"),rs("isgood"),rs("isvote"),rs("vote_num"))
评论: 8 | 引用: 0 | 查看次数: 697
发表评论