这类代码一般都事先定义成 函数、过程、类等,一般放在一共公共文件里便于调用;
根据定义类型,在需要使用的时候调用即可;
比如 事先定义了一个 函数
<%
'这是一个替换html标签的函数过程
Function HtmlDecode(ByVal fString)
If IsNull(fString) Or Trim(fString) = "" Then
PE_HtmlDecode = ""
Exit Function
End If
fString = Replace(fString, ">", ">")
fString = Replace(fString, "<", "<")
fString = Replace(fString, " ", " ")
HtmlDecode = fString
End Function
%>
在调用的地方使用即可;
使用:
<%response.write(HtmlDecode("我这里要替换 为空格!"))%>
'//替换非法数据的函数
Function Replace_Text(fString)
if isnull(fString) then
Replace_Text=""
exit function
else
fString=trim(fString)
fString=replace(fString,"'","''")
fString=replace(fString,";",";")
fString=replace(fString,"--","—")
'fString=replace(fString,"and","")
'fString=replace(fString,"or","")
fString=replace(fString,"select","")
fString=replace(fString,"insert","")
fString=replace(fString,"exec","")
fString=replace(fString,"delete","")
fString=replace(fString,"update","")
fString=replace(fString,"count","")
fString=replace(fString,"mid","")
fString=replace(fString,"truncate","")
fString=replace(fString,"%","")
fString=replace(fString,"chr","")
fString=replace(fString,"master","")
fString=replace(fString,"char","")
fString=replace(fString,"declare","")
fString=replace(fString,"*","")
fString=replace(fString,"from","")
fString=server.htmlencode(fString)
Replace_Text=fString
end if
End function
<%=Replace_Text("来源字段")%>
sub ()
...
end sub
<% Call Replace_Text("来源字段")%>
写成include文件 用的时候直接调函数不就行了 比如
funtion bbb(str)
里面是过滤代码
end functin
a='asdfad'
c=bbb(a)
就ok了