'Replace all HTML tag matches with the empty string strOutput = objRegExp.Replace(strHTML, "")
'Replace all < and > with < and > strOutput = Replace(strOutput, "<", "<") strOutput = Replace(strOutput, ">", ">")
stripHTML = strOutput 'Return the value of strOutput
Set objRegExp = Nothing End Function
%>
<% if Len(Request("txtHTML")) > 0 then %>
View of string with no HTML stripping:
<%=Request("txtHTML")%>
View of string with HTML stripping:
<%=StripHTML(Request("txtHTML"))%>
<% End If %>
--------------------------------------- 如何检测备注字段的字节数 视服务器操作系统语种不同,而采取不同的方法: 1.E文下,len(rs("field")),就行了.len("中文abc")=7 2.Z文下,复杂一点,len("中文abc")=5 lenB("中文abc")=10,所以需要自己写程序判断其长度. function strLen(str) dim i,l,t,c l=len(str) t=l for i=1 to l c=asc(mid(str,i,1)) if c<0 then c=c+65536 if c>255 then t=t+1 end if next strLen=t end function
------------------------------------ FSO自写自用的几个函数 ''''使用FSO修改文件特定内容的函数 function FSOchange(filename,Target,String) Dim objFSO,objCountFile,FiletempData Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True) FiletempData = objCountFile.ReadAll objCountFile.Close FiletempData=Replace(FiletempData,Target,String) Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True) objCountFile.Write FiletempData objCountFile.Close Set objCountFile=Nothing Set objFSO = Nothing End Function ''''使用FSO读取文件内容的函数 function FSOFileRead(filename) Dim objFSO,objCountFile,FiletempData Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True) FSOFileRead = objCountFile.ReadAll objCountFile.Close Set objCountFile=Nothing Set objFSO = Nothing End Function ''''使用FSO读取文件某一行的函数 function FSOlinedit(filename,lineNum) if linenum < 1 then exit function dim fso,f,temparray,tempcnt set fso = server.CreateObject("scripting.filesystemobject") if not fso.fileExists(server.mappath(filename)) then exit function set f = fso.opentextfile(server.mappath(filename),1) if not f.AtEndofStream then tempcnt = f.readall f.close set f = nothing temparray = split(tempcnt,chr(13)&chr(10)) if lineNum>ubound(temparray)+1 then exit function else FSOlinedit = temparray(lineNum-1) end if end if end function ''''使用FSO写文件某一行的函数 function FSOlinewrite(filename,lineNum,Linecontent) if linenum < 1 then exit function dim fso,f,temparray,tempCnt set fso = server.CreateObject("scripting.filesystemobject") if not fso.fileExists(server.mappath(filename)) then exit function set f = fso.opentextfile(server.mappath(filename),1) if not f.AtEndofStream then tempcnt = f.readall f.close temparray = split(tempcnt,chr(13)&chr(10)) if lineNum>ubound(temparray)+1 then exit function else temparray(lineNum-1) = lineContent end if tempcnt = join(temparray,chr(13)&chr(10)) set f = fso.createtextfile(server.mappath(filename),true) f.write tempcnt end if f.close set f = nothing end function ''''使用FSO添加文件新行的函数 function FSOappline(filename,Linecontent) dim fso,f set fso = server.CreateObject("scripting.filesystemobject") if not fso.fileExists(server.mappath(filename)) then exit function set f = fso.opentextfile(server.mappath(filename),8,1) f.write chr(13)&chr(10)&Linecontent f.close set f = nothing end function ''''读文件最后一行的函数 function FSOlastline(filename) dim fso,f,temparray,tempcnt set fso = server.CreateObject("scripting.filesystemobject") if not fso.fileExists(server.mappath(filename)) then exit function set f = fso.opentextfile(server.mappath(filename),1) if not f.AtEndofStream then tempcnt = f.readall f.close set f = nothing temparray = split(tempcnt,chr(13)&chr(10)) FSOlastline = temparray(ubound(temparray)) end if end function 还有,创建文件夹: sub CreateFolder(Foldername) Set afso = Server.CreateObject("Scripting.FileSystemObject") if afso.folderexists(server.mappath(Foldername))=true then else afso.createfolder(server.mappath(foldername)) end if set afso=nothing end sub
用法,createfolder(foldername)
---------------------------------------- ''检查字符串是否包含非法字符串 FUNCTION BadWords(strContent) DIM objRegExp Set objRegExp = new RegExp objRegExp.IgnoreCase = true objRegExp.Global = true objRegExp.Pattern = "李.{0,10}某.{0,10}人|他.{0,10}妈.{0,10}的|你.{0,10}他.{0,10}妈.{0,10}的|我操.{0,10}你妈" BadWords = objRegExp.Test(strContent) Set objRegExp = Nothing END FUNCTION
--------------------------------------- 取得网站的URL的根目录 '****************************** '||Function GetRootDir() '||Created by Cj, 2000/8/28 '||取得网站的URL的根目录 '****************************** Function GetRootDir() If Application("RootDir") <> "" And Not isNull(Application("RootDir")) then GetRootDir = Application("RootDir") Exit Function End if
dim strRoot, intRootEnd strRoot = Request.ServerVariables("SCRIPT_NAME") intRootEnd = Instr(2, strRoot, "/") if intRootEnd > 1 then strRoot = Left(strRoot, intRootEnd) End if Application.Lock() Application("RootDir") = strRoot Application.UnLock() GetRootDir = strRoot End Function
'HTML/********************* '将部分字符串转化为Html代码 function htmlencode2(str) dim result dim l if isNULL(str) then htmlencode2="" exit function end if l=len(str) result="" dim i for i = 1 to l select case mid(str,i,1) case "'" result=result+"’" 'case "" ' result=result+">" case chr(13) result=result+" " 'case chr(34) ' result=result+"" case "&" result=result+"&" case chr(32) 'result=result+" " if i+1<=l and i-1>0 then if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then result=result+" " else result=result+" " end if else result=result+" " end if case chr(9) result=result+" " case else result=result+mid(str,i,1) end select next htmlencode2=result end function
'字符串验证**************
'Emailcheck Function isEmail(val) isEmail=False if len(val)>0 then if instr(val,"@")>0 and instr(val,".")>0 and len(val)>5 then else exit function end if else exit function end if isEmail=true end function
" else response.write "" end if end sub Sub CategoryList(ParentID,num,Action) sql="select CategoryID,ParentID,CategoryName from Db_Category where ParentID="&ParentID set rs=server.createobject("adodb.recordset") rs.open sql,conn,1,1 if not rs.eof then Category = rs.getrows end if rs.close set rs=nothing snum = num + 1 str = Makeblank(snum,0) if isArray(Category) then for l=0 to ubound(Category,2) response.Write("
") for k=0 to ubound(Category,1) if k = ubound(Category,1) then '当显示CategoryName 时加[],其他不加 response.Write("
"&str&" [ "&Category(k,l)&"] "&"
") else response.Write("
"&Category(k,l)&" "&"
") end if next if Action = 1 then '添加目录 response.Write("
") end if '调用递归函数,列出下级目录 call CategoryList(Category(0,l),snum,Action) next set Category = nothing end if End Sub Sub CategorySel(CategoryID,num,SelectedID) sql="select CategoryID,ParentID,CategoryName from Db_Category where ParentID="&CategoryID set rs=server.createobject("adodb.recordset") rs.open sql,conn,1,1 if not rs.eof then Category = rs.getrows end if rs.close set rs = nothing snum = num + 1 str = Makeblank(snum,1) if isArray(Category) then for l=0 to ubound(Category,2) if Category(0,l) = SelectedID then '当显示已选择的ID时加[Selected],表示已选择 response.Write("") else response.Write("") end if '调用递归函数,列出下级目录 call CategorySel(Category(0,l),snum,SelectedID) next set Category = nothing end if End Sub Function Makeblank(num,Style) if Style = 0 then for i = 2 to num TempStr = TempStr&" " next Makeblank = TempStr&"├" else for i = 2 to num TempStr = TempStr&" " next Makeblank = TempStr&"└ " end if '不同的表格线:└┌┍┕┎┖┐┘┑┙┒┚┓┛├ ┤┝ ┥┞ ┦┼ ╄ ┽ ╅┣ ┫ End function %>
---------------------------------------- qq在线显示程序核心代码 <% Function GetURL(url) Set Retrieval = CreateObject("Microsoft.XMLHTTP") With Retrieval .Open "GET", url, False, "", "" .Send GetURL = .ResponseText End With Set Retrieval = Nothing End Function
Function qqonline(qqid) Dim T,Start,Length,PicURL '找到该用户界面的源代码 T=GetURL("";&qqid) '查找字符串ShowResult(的位置 Start=Instr(1,T,"ShowResult("+chr(34)) '查找字符串http://的位置 Start=Instr(Start,T,"http://"/;) '查找包含字符串的长度 Length=Instr(Start,T,chr(34)+","+chr(34))-Start PicURL=Mid(T,Start,Length) pic_right=right(picurl,5) pic_left=left(pic_right,1) if pic_left="2" then qqonline="在线" else qqonline="离线" end if End Function %><%=qqonline(24080411)%>
<% Dim objXML, strPath, str Set objXML = New clsXML
strPath = Server.MapPath(".") & "\New.xml"
objXML.createFile strPath, "Root" 'Or If using an existing XML file: 'objXML.File = "C:\File.xml"
objXML.createRootChild "Images"
'Here only one attribute is added to the Images/Image Node objXML.createChildNodeWAttr "Images", "Image", "id", "1" objXML.updateField "Images//Image[@id=1]", "super.gif" objXML.createRootNodeWAttr "Jobs", Array("Size", "Length", "Width"), _ Array(24, 31, 30) objXML.createRootNodeWAttr "Jobs", Array("Size", "Length", "Width"), _ Array(24, 30, 29) objXML.createRootNodeWAttr "Jobs", Array("Size", "Length", "Width"), _ Array(24, 31, 85)
'Notice that all three job nodes have size 24, all of those 'nodes will be updated objXML.updateField "Jobs[@Size=24]", "24's"
'Notice that only two nodes have the specified XPath, hence 'only two new child nodes will be added objXML.createChildNodeWAttr "Jobs[@Size=24 and @Length=31]", "Specs", _ Array("Wood", "Metal", "Color"), _ Array("Cedar", "Aluminum", "Green")
'It is always important to iterate through all of the nodes 'returned by this XPath query. For Each str In objXML.getField("Jobs[@Size=24]") Response.Write(str & " ") Next Set objXML = Nothing
Response.Redirect "New.xml" %>
clsXML.asp:
<% Class clsXML 'strFile must be full path to document, ie C:\XML\XMLFile.XML 'objDoc is the XML Object Private strFile, objDoc
'Set XML File and objDoc Public Property Let File(str) Set objDoc = Server.CreateObject("Microsoft.XMLDOM") objDoc.async = False strFile = str objDoc.Load strFile End Property
'Get XML File Public Property Get File() File = strFile End Property
'Create Blank XML File, set current obj File to newly created file Public Function createFile(strPath, strRoot) Dim objFSO, objTextFile Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.CreateTextFile(strPath, True) objTextFile.WriteLine("") objTextFile.WriteLine("<" & strRoot & "/>") objTextFile.Close Me.File = strPath Set objTextFile = Nothing Set objFSO = Nothing End Function
'Get XML Field(s) based on XPath input from root node Public Function getField(strXPath) Dim objNodeList, arrResponse(), i Set objNodeList = objDoc.documentElement.selectNodes(strXPath) ReDim arrResponse(objNodeList.length) For i = 0 To objNodeList.length - 1 arrResponse(i) = objNodeList.item(i).Text Next getField = arrResponse End Function
'Update existing node(s) based on XPath specs Public Function updateField(strXPath, strData) Dim objField For Each objField In objDoc.documentElement.selectNodes(strXPath) objField.Text = strData Next objDoc.Save strFile Set objField = Nothing updateField = True End Function
'Create node directly under root Public Function createRootChild(strNode) Dim objChild Set objChild = objDoc.createNode(1, strNode, "") objDoc.documentElement.appendChild(objChild) objDoc.Save strFile Set objChild = Nothing End Function
'Create a child node under root node with attributes Public Function createRootNodeWAttr(strNode, attr, val) Dim objChild, objAttr Set objChild = objDoc.createNode(1, strNode, "") If IsArray(attr) And IsArray(val) Then If UBound(attr)-LBound(attr) <> UBound(val)-LBound(val) Then Exit Function Else Dim i For i = LBound(attr) To UBound(attr) Set objAttr = objDoc.createAttribute(attr(i)) objChild.setAttribute attr(i), val(i) Next End If Else Set objAttr = objDoc.createAttribute(attr) objChild.setAttribute attr, val End If objDoc.documentElement.appendChild(objChild) objDoc.Save strFile Set objChild = Nothing End Function
'Create a child node under the specified XPath Node Public Function createChildNode(strXPath, strNode) Dim objParent, objChild For Each objParent In objDoc.documentElement.selectNodes(strXPath) Set objChild = objDoc.createNode(1, strNode, "") objParent.appendChild(objChild) Next objDoc.Save strFile Set objParent = Nothing Set objChild = Nothing End Function
'Create a child node(s) under the specified XPath Node with attributes Public Function createChildNodeWAttr(strXPath, strNode, attr, val) Dim objParent, objChild, objAttr For Each objParent In objDoc.documentElement.selectNodes(strXPath) Set objChild = objDoc.createNode(1, strNode, "") If IsArray(attr) And IsArray(val) Then If UBound(attr)-LBound(attr) <> UBound(val)-LBound(val) Then Exit Function Else Dim i For i = LBound(attr) To UBound(attr) Set objAttr = objDoc.createAttribute(attr(i)) objChild.SetAttribute attr(i), val(i) Next End If Else Set objAttr = objDoc.createAttribute(attr) objChild.setAttribute attr, val End If objParent.appendChild(objChild) Next objDoc.Save strFile Set objParent = Nothing Set objChild = Nothing End Function
'Delete the node specified by the XPath Public Function deleteNode(strXPath) Dim objOld For Each objOld In objDoc.documentElement.selectNodes(strXPath) objDoc.documentElement.removeChild objOld Next objDoc.Save strFile Set objOld = Nothing End Function End Class %>
------------------------------------------ 身份证真伪 'id 省份证号 'birthday生日,yyyy-mm-dd格式 'sex性别,值为"男:1","女:0" id = "460102800925121" birthday = "1980-09-25" sex = 1
IF idcard_check(id,birthday,sex) Then response.write "不错" else response.write "**" End if
Function idcard_check(id,birthday,sex) If len(id)<>15 and len(id)<>18 then idcard_check=false Exit Function Else For i=1 to len(id) temp=mid(id,i,1) If temp<"0" or temp>"9" Then idcard_check=False Exit Function End if Next bdl=left(birthday,4) & mid(birthday,6,2) & mid(birthday,9,2) bds=mid(birthday,3,2) & mid(birthday,6,2) & mid(birthday,9,2) If len(id)=15 Then If mid(id,7,6)<>bds Then idcard_check=False Exit Function End if If int(mid(id,15,1)) Mod 2 = 1 And sex=1 Then idcard_check=True Exit Function ElseIf int(mid(id,15,1)) Mod 2 = 0 And sex=0 Then idcard_check=True Exit Function Else idcard_check=False Exit Function End if Else If mid(id,7,8)<>bdl Then idcard_check=False Exit Function End if If int(mid(id,17,1)) Mod 2 = 1 And sex=1 Then idcard_check=False Exit Function ElseIf int(mid(id,17,1)) Mod 2 = 0 And sex=0 Then idcard_check=False Exit Function Else idcard_check=False Exit Function End if End if End if idcard_check=True End function 11="北京" 12="天津" 13="河北" 14="山西" 15="内蒙古" 21="辽宁" 22="吉林" 23="黑龙江" 31="上海" 32="江苏" 33="浙江" 34="安徽" 35="福建" 36="江西" 37="山东" 41="河南" 42="湖北" 43="湖南" 44="广东" 45="广西" 46="海南" 50="重庆" 51="四川" 52="贵州" 53="云南" 54="西藏" 61="陕西" 62="甘肃" 63="青海" 64="宁夏" 65="新疆" 71="台湾" 81="香港" 82="澳门" 91="国外"