如何将论坛帖子中的所有出现某个关键字的都替换成一个链接

来源:百度知道 编辑:UC知道 时间:2024/06/05 11:09:58
如何将论坛帖子中的所有出现某个关键子的都替换成一个链接
我用的是access数据库,asp论坛。比如说只要帖子中出现“好人”两个字,就全部替换成www.baidu.com怎么弄?谁能给个代码。
如果要加代码,是在哪个文件下加?是在showpost.asp 中加么?在哪个位置?在<td colSpan=2 vAlign=top height="100%" bgcolor=#F5FFE8><div style="OVERFLOW:auto;WIDTH:100%;font-size:14px;line-height:170%;">
<%
if instr("|"&SiteSettings("BannedUserPost")&"|"&Request.Cookies("BadUserList")&"|","|"&Rs1("UserName")&"|")>0 then
Response.Write "==============================<br> <font color=RED>该用户帖子已被过滤 </font><br>=============================="
else
content=UBBCode(Rs("content"))
Response.Write ""&content&""
%>这后面加么?
只替换贴子里面内容的某个关键字,而比如标题等其他内容出现了这个关键字也不替换
要写清楚代码,最好有详细说明。

很简单,你定义一个变量

<%
function haode(code)
if instr(code,"关键字")>0 then
haode=replace(code,"关键字","<a href=http://baidu.com target=_blank>关键字</a>")
else
haode=code
end if
end function
%>

在内容这里调用
content=haode(UBBCode(Rs("content")))

下面是我测试的例子,你可以试一下,没问题的
<%
function haode(code)
if instr(code,"关键字")>0 then
haode=replace(code,"关键字","<a href=http://baidu.com target=_blank>关键字</a>")
else
haode=code
end if
end function
response.write(haode("有关键字阿"))
%>