정규식 특정 태그 허용처리 함수 > 소스코드

본문 바로가기
사이트 내 전체검색


회원로그인

소스코드

asp | 정규식 특정 태그 허용처리 함수

페이지 정보

작성자 100K5 작성일13-07-26 11:20 조회62,318회 댓글0건

본문

<%

'//패턴으로 치환할수 있는 eregi_replace()함수를 구현
'//PHP에는 있으나 ASP에는 없기 때문
Function eregi_replace(pattern, replace, text)
 
Dim eregObj
 
Set eregObj = New RegExp
  
eregObj.Pattern = pattern '//패턴 설정
  
eregObj.IgnoreCase = True '//대소문자 구분 여부
  
eregObj.Global = True '//전체 문서에서 검색

eregi_replace = eregObj.Replace(text, replace) '//Replace String

End Function


'//허용태그 외의 모든 태그제거 함수
Function strip_tags(str,allowtags)

Dim content

Dim tags

content = str

tags = replace(allowtags,",","|")

content = eregi_replace("<(\/?)(?!\/|" & tags & ")([^<>]*)?>", "<$1$2>", content)

contents = eregi_replace("(javascript\:|vbscript\:)+","$1//",contents)

contents = eregi_replace

("(\.location|location\.|onload=|\.cookie|alert\(|window\.open\(|onmouse|onkey|onclick|view\-

source\:)+","//",contents) '//자바스크립트 실행방지

strip_tags = content

End Function


'//사용예
Dim permitTags, comment

permitTags = "br,a,img,table,b,font,div,center,embed"

comment = "<font color=red>허용하지 않은 태그</font>가<br>잘 <b>보이나요?</b><br><script></script>"

comment = comment & "<div align=center>아주 유용할꺼에요~</div><body><html><xmp><pre>"

response.write strip_tags(comment,permitTags)

%>

댓글목록

등록된 댓글이 없습니다.


사이트소개 개인정보취급방침 서비스이용약관 Copyright © kkujunhee.net All rights reserved.
상단으로

개인정보관리책임자 : 관리자

모바일 버전으로 보기