您的位置:程序门 -> web 开发 -> asp



急救,字符(脏话)过滤问题,请教高手啊


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


急救,字符(脏话)过滤问题,请教高手啊
发表于:2007-04-07 18:07:33 楼主
我刚学asp,自己试着写了个过滤代码,想实现对发表的脏话的过滤功能.
第一种写法是放在接收表单页的:
<%  
word=request.form( "content ")
str= "脏话关键词,用 ¦隔开 "
str=split(str, " ¦ ")
for   i=lbound(str)   to   ubound(str)
word=replace(word,str(i), "** ")
next
%>
上面我是想使用split和replace两个函数实现脏话过滤,我运行了,是可以通过的.
但是我又写了第二种方法,自定义了个过程,代码如下:
<%  
function   checkwords(word)
str= "脏话挂念词,用 ¦隔开 "
str=split(str, " ¦ ")
for   i=lbound(str)   to   ubound(str)
word=replace(word,str(i), "** ")
next
end   function
%>
然后我调用这个过程:
<%=checkwords(request.form( "
content "))%>
不知道为什么,却运行错误.显示不出表单的内容,到底错在哪儿?希望懂的指教啊.我都想了两天了.
发表于:2007-04-07 18:35:271楼 得分:0
调用格式不正确吧     试一下     <%   call   checkwords(request.form( "content "))   %>

如果不是的就按下面的办法试吧
第一种 <%=checkwords( "sfljsfljslfjsflj ")%> ,如查ok,那表明函数没有问题
接着     查看   表单有没有传值过来     response.write   request( "content ")
发表于:2007-04-07 19:17:532楼 得分:0
问题在于,你的函数没有返回值。
修改为

<%  
function   checkwords(word)
str= "脏话挂念词,用 ¦隔开 "
str=split(str, " ¦ ")
for   i=lbound(str)   to   ubound(str)
word=replace(word,str(i), "** ")
next
checkwords   =   word         '函数返回值,返回处理后的结果
end   function
%>
发表于:2007-04-07 20:22:033楼 得分:0
啊,太谢谢楼上的了,我试验了一下,确实是这么回事,那我还有个疑问:
checkwords   =   word
其中的checkwords应该是自定义的函数啊,那为什么要checkwords   =   word呢?函数名和值是个什么关系?我不懂.能详细解释下吗?
发表于:2007-04-07 20:44:114楼 得分:0
checkwords   =   word
返回函数的值为word

去看看书吧,


快速检索

最新资讯
热门点击