标题:[求助]如何替换掉非法字符,我在论坛上没有搜索到就来请教了
取消只看楼主
redmangame
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2004-8-23
 问题点数:0 回复次数:3 
[求助]如何替换掉非法字符,我在论坛上没有搜索到就来请教了

[求助]如何替换掉非法字符,我在论坛上没有搜索到就来请教了
高手可以举例吗


还有就是替换非法字符的代码一般是放在处理信息的文件里还是放在输出信息的文件里呢
新手上路问题多多

搜索更多相关主题的帖子: 字符 搜索 
2006-01-22 20:53
redmangame
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2004-8-23
得分:0 
太深傲了,天啊SAVE。ASP
<%
function filtrate(con,length)
length=Cint(length)
con=replace(con,"'","''")
con=replace(con,chr(34),"""")
con=replace(con,"&","&amp;")
con=replace(con," ","&nbsp;&nbsp;")
con=replace(con,"<","&lt;")
con=replace(con,">","&gt;")
if len(con)>length then
con=left(con,length)
end if
filtrate=con
end function
%>
<%
dim title,con
title=request.form("title")
con=request.form("con")
if trim(title)="" or trim(con)="" then
response.write"所填标题和内容不能为空"
end if
if len(request.form("title"))>5 or len(request.form("con"))>200 then
response.write"所填标题和内容过长"
end if
set rs= Server.CreateObject("adodb.recordset")
sql= "select * from guestbook"
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("con")=con
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write("成功<A HREF=list.asp>返回</A>")
%>
这样吧

我是菜鸟
2006-01-23 17:46
redmangame
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2004-8-23
得分:0 

那个是什么 这样写对吗
<%
function con(contentTemp,length)
length=Cint(length)
contentTemp=replace(contentTemp,"'","''")
contentTemp=replace(contentTemp,chr(34),"""")
contentTemp=replace(contentTemp,"&","&amp;")
contentTemp=replace(contentTemp," ","&nbsp;&nbsp;")
contentTemp=replace(contentTemp,"<","&lt;")
contentTemp=replace(contentTemp,">","&gt;")
if len(contentTemp)>length then
contentTemp=left(contentTemp,length)
end if
com=contentTemp
end function
%>
<%
dim title,con
title=request.form("title")
con=request.form("con")
if trim(title)="" or trim(con)="" then
response.write"所填标题和内容不能为空"
else
set rs= Server.CreateObject("adodb.recordset")
sql= "select * from guestbook"
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("con")=con
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write("<A HREF=list.asp>返回</A>")
end if
%>


我是菜鸟
2006-01-24 21:27
redmangame
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2004-8-23
得分:0 
错误的原因是没有引用,看了几天的代码总算给发现了,哈哈


strSTR = LCase(strSTR)
strSTR = Replace(strSTR,"'","")
strSTR = Replace(strSTR,"*","")
strSTR = Replace(strSTR,"?","")
strSTR = Replace(strSTR,"(","")
strSTR = Replace(strSTR,")","")
strSTR = Replace(strSTR,"<","")
strSTR = Replace(strSTR,">","")
strSTR = Replace(strSTR,".","")
strSTR = Replace(strSTR,"and","")
strSTR = Replace(strSTR,"exec","")
strSTR = Replace(strSTR,"insert","")
strSTR = Replace(strSTR,"delete","")
strSTR = Replace(strSTR,"update","")
strSTR = Replace(strSTR,"select","")
strSTR = Replace(strSTR,"count","")
strSTR = Replace(strSTR,"master.","")
strSTR = Replace(strSTR,"%20from","")
strSTR = Replace(strSTR,";","")
strSTR = Replace(strSTR,"mid","")
strSTR = Replace(strSTR,"chr(37)","")
strSTR = Replace(strSTR,"=","")
strSTR = Replace(strSTR,"set","")

[此贴子已经被作者于2006-1-25 15:20:57编辑过]


我是菜鸟
2006-01-25 15:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-43722-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.817565 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved