1.单个关键字 突出显示
用Replace函数,格式如下:
要替换的字符串:strA=trim(request("keyword"))
要替换成的字符串:strB="<font color=red>" strA "</font>"
content是文章的内容
Response.Write Replace(content,strA,strB)
或者
Response.Write(Replace(content,strA,strB))
2.多个关键字 突出显示关键字
用到split函数
dim keywords
keywords=split(request("keyword"))
经过上述步骤,可以得到一个包含“综合受理”和“文书流转”两个字符串的数组(一维)
然后利用一个for循环语句来将数组的内容转做where子句的查询条件
dim i,temp
for i=LBound(keywords) to UBound(keywords) step 1
//LowBound是获取数组的下标,UpBound是获取数组的上标
temp=temp "content like '%" Cstr(keywords(i)) "%' and "
next
通过上述语句,最终的temp的内容是:
content like '%综合受理%' and content like '%文书受理%' and
后面多了一个and
因此在where子句可以增加多一个条件来结束查询语句。sql语句如下:
sql="select id,title,content from [table1] where "&temp&" id>0"
//表中的id是自动编号,肯定大于0,只是用来补充完成子句