余志国网站设计工作室是专业从事义乌网站建设、义乌外贸网站建设、义乌网站制作、义乌网站设计的专业义乌网站建设工作室,是义乌外贸网站建设专家!

ASP搜索关键词时结果用红色显示代码

分类:程序开发 Tags: asp 关键词 评论:0 浏览:4527 最近更新时间:2015/9/22 22:03:50

我们在使用baidu、google搜索时,搜索结果中显示的搜索关键词会显示红色,这是如何实现的呢?下面教大家用ASP能够简单实现此功能。

<%
response.write replace(rs("字段X"),searchname,"<font color=#FF0000>" & searchname & "</font>")
%>

说明:rs为记录集对象,searchname为搜索的关键词


正则

Function Highlight(strText, strFind, strBefore, strAfter)   
Dim nPos   
Dim nLen   
Dim nLenAll   
nLen = Len(strFind)   
nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1   
Highlight = strText   
If nLen > 0 And Len(Highlight) > 0 Then  
nPos = InStr(1, Highlight, strFind, 1)   
Do While nPos > 0   
Highlight = Left(Highlight, nPos - 1) & _   
strBefore & Mid(Highlight, nPos, nLen) & strAfter & _   
Mid(Highlight, nPos + nLen)   
nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)   
Loop  
End If  
End Function  
 
Response.Write Highlight(myText, "someword", "<font color=red>", "</font>")


本文地址:/349/
  • 相关文章
  • 推荐文章
  • 最新文章
发表评论





您的IP:18.97.14.91,来自:

留言

 


免费咨询
建站咨询热线
15967985565
QQ: 358758308 Skype: yuzhiguo Facebook: yuzhiguo Email