文章中添加关键字链接

代码:
<%
function  keywords_link(byval str)  
dim rstags  
'问题1解决办法  
set rstags=conn.execute("select * from [tags] order by len(title) desc")  
while not rstags.eof  
str=p_replace(str,rstags("title"),""&rstags("title")&"")    
rstags.movenext  
wend  
rstags.close  
set rstags=nothing  
keywords_link=str  
end function  

'问题2解决函数 避免重复替换  
function p_replace(byval content,byval asp,byval htm)  
dim Matches,objRegExp,strs,i  
strs=content  
Set objRegExp = New Regexp'设置配置对象  
objRegExp.Global = True'设置为全文搜索  
objRegExp.IgnoreCase = True  
objRegExp.Pattern = "(\]+\>.+?\<\/a\>)|(\]+\>)"  
Set Matches =objRegExp.Execute(strs)'开始执行配置  
'替换正则表达式  
i=0  
Dim MyArray()  
For Each Match in Matches  
ReDim Preserve MyArray(i)  
MyArray(i)=Mid(Match.Value,1,len(Match.Value))  
strs=replace(strs,Match.Value,"<"&i&">")  
i=i+1  
Next  
'没有正则时候  
if i=0 then  
content=replace(content,asp,htm)  
p_replace=content  
exit function  
end if  
'特殊字符替换  
strs=replace(strs,asp,htm)  
'替换回去  
for i=0 to ubound(MyArray)  
strs=replace(strs,"<"&i&">",MyArray(i))  
next  
p_replace=strs  
end function  
%>



使用:
<%=keywords_link(rs("content"))%>即可


上一篇: 多图片产品展示
下一篇: 这些话也许是你一生都在寻找的,句句深入人心(转)
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 3518
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 300 字 | UBB代码 开启 | [img]标签 关闭