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

본문 바로가기

사이트 내 전체검색


소스코드

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

페이지 정보

작성자 100K5 작성일13-07-26 11:20 조회63,168회 댓글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 © 소유하신 도메인. All rights reserved.상단으로
TEL. 00-000-0000 FAX. 00-000-0000 서울 강남구 강남대로 1
대표:홍길동 사업자등록번호:000-00-00000 개인정보관리책임자:홍길동
PC 버전으로 보기