伊凡空間
關於部落格
這個部落落是到處拍和聚會的記錄

開始接拍活動紀錄,人像攝影,有興趣可留言^^
  • 99711

    累積人氣

  • 54

    今日人氣

    0

    訂閱人氣

2011.07.01_ASP 規則運算式

Function RemoveHTML_A(strText)

    Dim nPos1
    Dim nPos2
    nPos1 = InStr(strText, "<")
    Do While nPos1>0
        nPos2 = InStr(nPos1+1, strText, ">")
        If nPos2>0 Then
            strText = Left(strText, nPos1 - 1) & Mid(strText, nPos2 + 1)
        Else
            Exit Do
        End If
        nPos1 = InStr(strText, "<")
    Loop
    RemoveHTML_A = strText
End Function

Asp過濾Html代碼方法一 

Function RemoveHTML(strHTML) 
Dim objRegExp, Match, Matches 
Set objRegExp = New Regexp 
objRegExp.IgnoreCase = True 
objRegExp.Global = True 
'取閉合的<> 
objRegExp.Pattern = "<.+?>" 
'進行匹配 
Set Matches = objRegExp.Execute(strHTML) 
' 遍歷匹配集合,並替換掉匹配的項目 
For Each Match in Matches 
strHtml=Replace(strHTML,Match.Value,"") 
Next 
RemoveHTML=strHTML 
Set objRegExp = Nothing 
End Function 

過濾圖片規則運算式 
<img.+?> 

 

Asp過濾Html代碼方法二 

Function delHtml(strHtml) 
Dim objRegExp, strOutput 
Set objRegExp = New Regexp ' 建立規則運算式 
objRegExp.IgnoreCase = True ' 設置是否區分大小寫 
objRegExp.Global = True '是匹配所有字串還是只是第一個 
objRegExp.Pattern = "(<[a-zA-Z].*?>)|(<[/][a-zA-Z].*?>)
" ' 設置模式引號中的是規則運算式,用來找出html標籤 
strOutput = objRegExp.Replace(strHtml, "") '將html標籤去掉 
strOutput = Replace(strOutput, "<", "<") '防止非html標籤不顯示 
strOutput = Replace(strOutput, ">", ">")  
delHtml = strOutput 
Set objRegExp = Nothing 
End Function 
'srt1是你要去除html代碼字串,可以其它任何地方讀取過來。 
str1 = "& lt;meta http-equiv=""refresh"" content=""0;URL=apple/default.htm"">& lt;title>正</3>在轉到 ... ...</title>"  
'應用函數 
Response.Write(delHtml(str1)) 




Asp過濾Html代碼方法三
 
轉化html標籤為code代碼 
function coder(str) 
   dim i 
   if isnull(str) then : coder="" : exit function : end if 
   for i = 1 to len(str) 
     select case mid(str,i,1) 
       case "<"      : coder = coder &"&lt;" 
       case ">"      : coder = coder &"&gt;"      
       case "&"      : coder = coder &"&amp;" 
       case chr(9)   : coder = coder &"&nbsp; &nbsp; " 
       case chr(13) : coder = coder &"<br>" 
       case chr(32) : coder = coder &"&nbsp;" 
       case chr(34) : coder = coder &"&quot;" 
       case chr(39) : coder = coder &"&#39;" 
       case else     : coder = coder & mid(str,i,1) 
     end select 
   next 
end function  


 
過濾javascript字元 
function movejs(str) 
dim objregexp,str1 
    set objregexp=new regexp 
    objregexp.ignorecase =true 
    objregexp.global=true 
    objregexp.pattern="<script.+?</script>" 
    a=objregexp.replace(str,"") 
    objregexp.pattern="<[^<]+>" 
    movejs=objregexp.replace(a,"") 
end function  

過濾html標籤只剩<br> 
function filterhtml(byval fstring) 
     if isnull(fstring) or trim(fstring)="" then 
         filterhtml="" 
         exit function 
     end if 
     
     fstring = replace(fstring, "<br />", "[br]") 
     fstring = replace(fstring, "<br>", "[br]") 
     
     '過濾html標籤 
     dim re 
     set    re = new    regexp 
     re.ignorecase=true 
     re.global=true 
     re.pattern="<(.+?)>" 
     fstring = re.replace(fstring, "") 
     set    re=nothing 
     
     fstring = replace(fstring, "[br]", "<br />") 
     filterhtml = fstring 
end function
'Asp 規則運算式 過濾 所有 html 標記 :
Function LoseHtml(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "</*[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseHtml = ClsTempLoseStr
End function
'Asp 規則運算式 過濾 style 標記 :
Function LoseStyleTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "(<style)+[^<>]*>[^]*(</style>)+"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseStyleTag = ClsTempLoseStr
Set regEx = Nothing
End Function
'Asp 規則運算式 過濾 層 div 標記 :
Function LoseDivTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<(/){0,1}div[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseDivTag = ClsTempLoseStr
Set regEx = Nothing
End Function

'Asp 規則運算式 過濾 連結 a 標記 :
Function LoseATag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<(/){0,1}a[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseATag = ClsTempLoseStr
Set regEx = Nothing
End Function

'Asp 規則運算式 過濾 字體 font 標記 :
Function LoseFontTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<(/){0,1}font[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseFontTag = ClsTempLoseStr
Set regEx = Nothing
End Function
 
'Asp 規則運算式 過濾 span 標記 :
Function LoseSpanTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<(/){0,1}span[^<>]*>"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseSpanTag = ClsTempLoseStr
Set regEx = Nothing
End Function
 
'Asp 規則運算式 過濾 object 標記 :
Function LoseObjectTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "<object.*?/object>"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseObjectTag = ClsTempLoseStr
Set regEx = Nothing
End Function

'Asp 規則運算式 過濾 iframe 標記:
Function LoseIFrameTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "(<iframe){1,}[^<>]*>[^]*(</iframe>){1,}"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseIFrameTag = ClsTempLoseStr
Set regEx = Nothing
End Function

'Asp 規則運算式 過濾 script :
Function LoseScriptTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "(<script){1,}[^<>]*>[^]*(</script>){1,}"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseScriptTag = ClsTempLoseStr
Set regEx = Nothing
End Function

'Asp 規則運算式 過濾 Class 標記 :
Function LoseClassTag(ContentStr)
Dim ClsTempLoseStr,regEx
ClsTempLoseStr = Cstr(ContentStr)
Set regEx = New RegExp
regEx.Pattern = "(class=){1,}(""|'){0,1}S+(""|'|>|s){0,1}"
regEx.IgnoreCase = True
regEx.Global = True
ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")
LoseClassTag = ClsTempLoseStr
Set regEx = Nothing
End Function
 
'字串替換 Replace 的規則運算式 :
Function ReplaceReg(str,patrn,replStr,Ignor)
'=========================================
'參數解釋:
'str 原來的字串
'patrn 要替換的字串(規則運算式)
'replStr 要替換成的字串
'Ignor 是否區分大小寫(1不區分,0區分)
'=========================================
Dim regEx ' 建立變數。
If Ingor=1 Then Ingor=true else Ingor=false
Set regEx = New RegExp ' 建立規則運算式。
regEx.Pattern = patrn ' 設置模式。
regEx.IgnoreCase = Ignor ' 設置是否區分大小寫。
regEx.Global=True
ReplaceReg = regEx.Replace(str,replStr) ' 作替換。
End Function
'例如 將 www.mawendong.com 替換成 <a href="http://www.mawendong.com">www.mawendon.com</a>
'Response.Write(ReplaceReg("www.weblank.com","www.mawendon.com","<a href=""http://www.mawendon.com"">www.mawendon.com</a>",1))


提交資訊轉換HTML

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=server.htmlencode(fString)
Replace_Text=fString
end if 
end function


 

 
資訊過濾

Function Replace_Text2(fString)
If Not IsNull(fString) Then
fString = trim(fString)
fString = replace(fString, ";", ";")     '分號過濾
fString = replace(fString, "--", "——") '--過濾
fString = replace(fString, "%20", "")    '特殊字元過濾
fString = replace(fString, "==", "")     '==過濾
fString = replace(fString, ">", "&gt;")
fString = replace(fString, "<", "&lt;")
fString = Replace(fString, CHR(32), " ")   '&nbsp;
fString = Replace(fString, CHR(9), " ")    '&nbsp;
fString = Replace(fString, CHR(34), "&quot;")
fString = Replace(fString, CHR(39), "'") '單引號過濾
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")
Replace_Text = fString
End If
End Function
'過濾SQL非法字元
Function checkStr(Chkstr)
dim Str:Str=Chkstr
if isnull(Str) then
   checkStr = ""
   exit Function
else
   Str=replace(Str,"'","")
   Str=replace(Str,";","")
   Str=replace(Str,"--","")
   checkStr=Str
end if
End Function


 


 

 
'過濾(傳遞方式GET/POST/COOKIES)指定字元
'--------定義部份------------------
Dim XH_Post,XH_Get,XH_In,XH_Inf,XH_Xh,XH_db,XH_dbstr
'自訂需要過濾的字串,用 "|" 分隔
XH_In = "and|exec|insert|select|delete%20from|update|count|*|%|chr|mid|master|truncate|char|declare|drop%20table|from|net%20user|xp_cmdshell|/add|net%20localgroup%20administrators|Asc|char"
'----------------------------------
XH_Inf = split(XH_In,"|")
'--------POST部份------------------
If Request.Form<>"" Then
For Each XH_Post In Request.Form
For XH_Xh=0 To Ubound(XH_Inf)
If Instr(LCase(Request.Form(XH_Post)),XH_Inf(XH_Xh))<>0 Then
Response.Write "<Script Language=JavaScript>alert('請不要在參數中包含非法字元嘗試注入!');</Script>"
Response.Write "非法操作!系統做了如下記錄↓<br>"
Response.Write "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
Response.Write "操作時間:"&Now&"<br>"
Response.Write "動作頁面:"&Request.ServerVariables("URL")&"<br>"
Response.Write "提交方式:POST<br>"
Response.Write "提交參數:"&XH_Post&"<br>"
Response.Write "提交資料:"&Request.Form(XH_Post)
Response.End
End If
Next
Next
End If
'----------------------------------


 

 
'--------GET部份-------------------
If Request.QueryString<>"" Then
For Each XH_Get In Request.QueryString
For XH_Xh=0 To Ubound(XH_Inf)
If Instr(LCase(Request.QueryString(XH_Get)),XH_Inf(XH_Xh))<>0 Then
Response.Write "<Script Language=JavaScript>alert('請不要在參數中包含非法字元嘗試注入!');</Script>"
Response.Write "非法操作!系統做了如下記錄↓<br>"
Response.Write "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
Response.Write "操作時間:"&Now&"<br>"
Response.Write "動作頁面:"&Request.ServerVariables("URL")&"<br>"
Response.Write "提交方式:GET<br>"
Response.Write "提交參數:"&XH_Get&"<br>"
Response.Write "提交資料:"&Request.QueryString(XH_Get)
Response.End
End If
Next
Next
End If
'----------------------------------
'--------COOKIE部份-------------------
If Request.Cookies<>"" Then
For Each XH_Cookie In Request.Cookies
For XH_Xh=0 To Ubound(XH_Inf)
If Instr(LCase(Request.Cookies(XH_Cookie)),XH_Inf(XH_Xh))<>0 Then
Response.Write "非法操作!系統做了如下記錄↓<br>"
Response.Write "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
Response.Write "操作時間:"&Now&"<br>"
Response.Write "動作頁面:"&Request.ServerVariables("URL")&"<br>"
Response.Write "提交方式:Cookie<br>"
Response.Write "提交參數:"&XH_Cookie&"<br>"
Response.Write "提交資料:"&Request.Cookies(XH_Cookie)
Response.End
End If
Next
Next
End If


 

 
發現網頁不存在就寄送Email

<% @language="vbscript" %>
<% Option Explicit %>
<%
Dim strPage, strReferer, strMessage
Dim objSMTP
' Log the offending page
strPage = Request.ServerVariables("HTTP_URL")
' Log the referer
strReferer = Request.ServerVariables("HTTP_REFERER")
' Set up the email component
Set objSMTP = Server.CreateObject("JMail.Message")
objSMTP.From = "you@yourdomain.com"
objSMTP.FromName = "Your Domain"
objSMTP.Subject = "404 Error Logged"
objSMTP.AddRecipient("you@yourdomain.com")
' Write the message
strMessage = "Requested page: " & strPage & vbCrLf & vbCrLf
If strReferer <> "" Then
strMessage = strMessage & "Referer: " & strReferer
Else
strMessage = strMessage "The visitor typed the address in"
End If
objSMTP.Body = strMessage
' Send the message
objSMTP.Send("mail.jzxue.com")
' Tidy up
objSMTP.ClearRecipients
objSMTP.Close()
Set objSMTP = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>404 Page Not Found</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body>
<h1>404 Page Not Found Error</h1>
<p>
Appropriate message here.
</p>
</body>
</html>
<% @language="vbscript" %>
<% Option Explicit %>
<%
Dim strPage, strReferer, strMessage
Dim objSMTP
' Log the offending page
strPage = Request.ServerVariables("HTTP_URL")
' Log the referer
strReferer = Request.ServerVariables("HTTP_REFERER")
' Set up the email component
Set objSMTP = Server.CreateObject("JMail.Message")
objSMTP.From = "you@yourdomain.com"
objSMTP.FromName = "Your Domain"
objSMTP.Subject = "404 Error Logged"
objSMTP.AddRecipient("you@yourdomain.com")
' Write the message
strMessage = "Requested page: " & strPage & vbCrLf & vbCrLf
If strReferer <> "" Then
strMessage = strMessage & "Referer: " & strReferer
Else
strMessage = strMessage "The visitor typed the address in"
End If
objSMTP.Body = strMessage
' Send the message
objSMTP.Send("mail.jzxue.com")
' Tidy up
objSMTP.ClearRecipients
objSMTP.Close()
Set objSMTP = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>404 Page Not Found</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
</head>
<body>
<h1>404 Page Not Found Error</h1>
<p>
Appropriate message here.
</p>
</body>
</html>
 
判斷圖片是否存在

function CheckURL(byval A_strUrl)
set XMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
XMLHTTP.open "HEAD",A_strUrl,false
XMLHTTP.send()
CheckURL=(XMLHTTP.status=200)
set XMLHTTP = nothing
end function
Dim imgurl
imgurl="UploadFiles/2007829144940734.gif"
if CheckURL(imgurl) then
response.write "圖片存在"
else
response.write "圖片不存在"
end if
判斷遠程圖片是否存在[js代碼]
{
var oReq = new ActiveXObject("Microsoft.XMLHTTP")
oReq.open("Get","UploadFiles/2007829144941621.gif",false);
oReq.send();
//alert(oReq.status)
if(oReq.status==404)
alert('不存在');
else
alert("存在")
}

資料轉載至[IT姜的異想世界]
http://itgroup.blueshop.com.tw/yaliha2000/2557?n=convew&i=118068
相簿設定
標籤設定
相簿狀態