티스토리 뷰
'******************************************************
'* Function strip_tags(str) As String
'* 태그 제거하고 반환
'*
'* Function strip_tags2(str, allowtags) As String
'* allowtags 태그들을 제외한 태그 제거하고 반환
'******************************************************
Function strip_tags( strHTML )
If NOT isset(strHTML) Then Exit Function
Dim objRegExp, strOutput
Set objRegExp = New Regexp
With objRegExp
.IgnoreCase = True
.Global = True
.Pattern = "<(.|\n)+?>" '// s/<(.*?)>//g 또는 s/<[a-zA-Z\/][^>]*>//g
strOutput = .Replace(strHTML, "") 'Replace all HTML tag matches with the empty string
End With
'Replace all < and > with < and >
'strOutput = Replace(strOutput, "<", "<")
'strOutput = Replace(strOutput, ">", ">")
strip_tags = strOutput 'Return the value of strOutput
Set objRegExp = Nothing
End Function
'// strip_tags2("문자열", "b,strong,font,br,p,table,tr,td")
Function strip_tags2( str , allowtags )
Dim content, tags
If NOT isset(str) Then Exit Function
content = str
tags = replace(allowtags,",","|")
'content = preg_replace("<(\/?)(?!\/|" & tags & ")([^<>]*)?>", "<$1$2>", content)
content = preg_replace("<(\/?)(?!\/|" & tags & ")([^<>]*)?>", "", content)
content = preg_replace("(javascript\:|vbscript\:)+","$1//",content)
content = preg_replace("(\.location|location\.|onload=|\.cookie|alert\(|window\.open\(|onmouse|onkey|onclick|view\-source\:)+","//",content) '//자바스크립트 실행방지
strip_tags2 = content
End Function
Function strip_html(strHTML)
If NOT isset(strHTML) Then Exit Function
Dim objRegExp, strOutput
Set objRegExp = New Regexp
With objRegExp
.IgnoreCase = True
.Global = True
.Pattern = "?(?i:script|embed|object|frameset|frame|iframe|meta|link|style)(.|\n)*?>"
strOutput = .Replace(strHTML, "") 'Replace all HTML tag matches with the empty string
End With
'Replace all < and > with < and >
'strOutput = Replace(strOutput, "<", "<")
'strOutput = Replace(strOutput, ">", ">")
strip_html = strOutput 'Return the value of strOutput
Set objRegExp = Nothing
End Function
'// http://www.codeproject.com/Articles/639/Removing-HTML-from-the-text-in-ASP
Function RemoveHTML(strText)
Dim TAGLIST : TAGLIST = "" '// allow tags
'TAGLIST = ";!--;!DOCTYPE;A;ACRONYM;ADDRESS;APPLET;AREA;B;BASE;BASEFONT;" &_
' "BGSOUND;BIG;BLOCKQUOTE;BODY;BR;BUTTON;CAPTION;CENTER;CITE;CODE;" &_
' "COL;COLGROUP;COMMENT;DD;DEL;DFN;DIR;DIV;DL;DT;EM;EMBED;FIELDSET;" &_
' "FONT;FORM;FRAME;FRAMESET;HEAD;H1;H2;H3;H4;H5;H6;HR;HTML;I;IFRAME;IMG;" &_
' "INPUT;INS;ISINDEX;KBD;LABEL;LAYER;LAGEND;LI;LINK;LISTING;MAP;MARQUEE;" &_
' "MENU;META;NOBR;NOFRAMES;NOSCRIPT;OBJECT;OL;OPTION;P;PARAM;PLAINTEXT;" &_
' "PRE;Q;S;SAMP;SCRIPT;SELECT;SMALL;SPAN;STRIKE;STRONG;STYLE;SUB;SUP;" &_
' "TABLE;TBODY;TD;TEXTAREA;TFOOT;TH;THEAD;TITLE;TR;TT;U;UL;VAR;WBR;XMP;"
Const BLOCKTAGLIST = ";APPLET;EMBED;FRAMESET;HEAD;NOFRAMES;NOSCRIPT;OBJECT;SCRIPT;STYLE;"
Dim nPos1, nPos2, nPos3, strResult, strTagName, bRemove, bSearchForBlock
nPos1 = InStr(strText, "<")
Do While nPos1 > 0
nPos2 = InStr(nPos1 + 1, strText, ">")
If nPos2 > 0 Then
strTagName = Mid(strText, nPos1 + 1, nPos2 - nPos1 - 1)
strTagName = Replace(Replace(strTagName, vbCr, " "), vbLf, " ")
nPos3 = InStr(strTagName, " ")
If nPos3 > 0 Then
strTagName = Left(strTagName, nPos3 - 1)
End If
If Left(strTagName, 1) = "/" Then
strTagName = Mid(strTagName, 2)
bSearchForBlock = False
Else
bSearchForBlock = True
End If
If InStr(1, TAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
bRemove = True
If bSearchForBlock Then
If InStr(1, BLOCKTAGLIST, ";" & strTagName & ";", vbTextCompare) > 0 Then
nPos2 = Len(strText)
nPos3 = InStr(nPos1 + 1, strText, "" & strTagName, vbTextCompare)
If nPos3 > 0 Then
nPos3 = InStr(nPos3 + 1, strText, ">")
End If
If nPos3 > 0 Then
nPos2 = nPos3
End If
End If
End If
Else
bRemove = False
End If
If bRemove Then
strResult = strResult & Left(strText, nPos1 - 1)
strText = Mid(strText, nPos2 + 1)
Else
strResult = strResult & Left(strText, nPos1)
strText = Mid(strText, nPos1 + 1)
End If
Else
strResult = strResult & strText
strText = ""
End If
nPos1 = InStr(strText, "<")
Loop
strResult = strResult & strText
RemoveHTML = strResult
End Function
'웹프로그래밍 > ASP Classic' 카테고리의 다른 글
| Classic ASP 에서 Server.Mappath로 IIS 가상 디렉터리의 물리 경로 구하기 (0) | 2012.07.12 |
|---|---|
| Classic ASP Memcached COM 컴포넌트 (0) | 2012.04.09 |
| 문자열을 JSON 형식으로 만들때 Escape (0) | 2012.01.31 |
| Classic ASP euc-kr 페이지에서 jQuery Ajax 한글 깨짐 해결 (1) | 2011.08.25 |
| Classic ASP에서 XML 파싱 이후 역정렬 목록 뽑기 (0) | 2011.08.25 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- mssql
- Debug
- PHP
- macos
- ASP
- API
- IOS
- Prototype
- laravel
- Wordpress
- classic asp
- javascript
- nodejs
- git
- Mac
- 워드프레스
- Linux
- 안드로이드
- Android
- JQuery
- IE
- iis
- CSS
- 한글
- centos
- nginx
- sencha touch
- iphone
- Docker
- JSON
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함