11.Nas_1


새창 작성 수정 목록 링크 Edit G카랜다 HDD HDD HDD 게시물 주소 복사


[ClassicASP] 모든 태그 제거 & 허용태그 외의 모든 html 태그 제거 (2012-04-18 수정)

♨ 카랜더 일정 :
  • 링크

  • 첨부

  • 컨텐츠 정보

    본문

    \r\n
    \r\n
    [ClassicASP] 모든 태그 제거 & 허용태그 외의 모든 html 태그 제거 (2012-04-18 수정)글자 확대 글자 축소
    \r\n
      2012-04-17 22:22 Hit.560 트랙백주소 게시글을 twitter로 보내기 게시글을 facebook으로 보내기 게시글을 Me2Day로 보내기 이 게시글을 요즘으로 보내기 게시글을 구글로 북마크 하기 게시글을 네이버로 북마크 하기
    \r\n
    \r\n
    \r\n
    \r\n
    <% Option Explicit %>
    \r\n

    <%
    \r\n
    \r\n
    ' =========================================================
    \r\n
    ' 패턴으로 치환할수 있는 eregi_replace()함수
    \r\n
    ' PHP에는 있으나 ASP에는 없기 때문
    \r\n
    ' =========================================================
    \r\n
    Function eregi_replace(pattern, replace, text)
    \r\n
     Dim eregObj
    \r\n
     
    \r\n
     Set eregObj = New RegExp
    \r\n
     
    \r\n
     eregObj.Pattern = pattern '패턴 설정
    \r\n
     eregObj.IgnoreCase = True '대소문자 구분 여부
    \r\n
     eregObj.Global = True '전체 문서에서 검색
    \r\n
     
    \r\n
     eregi_replace = eregObj.Replace(text, replace) 'Replace String
    \r\n
    End Function
    \r\n
     
    \r\n
     
    \r\n
    ' =========================================================
    \r\n
    ' 모든 태그제거
    \r\n
    ' 사용법 : strip_tags1(content)
    \r\n
    ' content = "....."
    \r\n
    ' strip_tags2(content)
    \r\n
    ' =========================================================
    \r\n
    Function strip_tags1(str)
    \r\n
      Dim content
    \r\n

      content = str  
    \r\n
      content = eregi_replace("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>","",content)  ' all
    \r\n
      content = eregi_replace("<(no)?script[^>]*>.*?</(no)?script>","",content)  ' scripts
    \r\n
      content = eregi_replace("<style[^>]*>.*</style>", "", content)  ' style
    \r\n
      content = eregi_replace("<(\""[^\""]*\""|\'[^\']*\'|[^\'\"">])*>","",content)  ' TAGS
    \r\n
      content = eregi_replace("<\\w+\\s+[^<]*\\s*>","",content)  ' nTAGS
    \r\n
      content = eregi_replace("&[^;]+;","",content)  ' entity_refs
    \r\n
      content = eregi_replace("\\s\\s+","",content)  ' whitespace
    \r\n

      strip_tags1 = content
    \r\n
    End Function
    \r\n
     
    \r\n
     
    \r\n
    ' =========================================================
    \r\n
    ' 허용태그 외의 모든 태그제거
    \r\n
    ' 사용법 : strip_tags2(content, allowtags)
    \r\n
    ' content = "....."
    \r\n
    ' allowtags = "br,a,img,table,b,font,div,center,embed"  ' 허용 ※ 태그 붙여서 연속으로, 공백 오류발생
    \r\n
    ' strip_tags2(content, allowtags)
    \r\n
    ' =========================================================
    \r\n
    Function strip_tags2(str,allowtags)
    \r\n
      Dim content, tags
    \r\n
     
    \r\n
      content = str
    \r\n
      tags = replace(allowtags,",","|")
    \r\n
      content = eregi_replace("<(/?)(?!/|" & tags & ")([^<>]*)?>","<$1$2&gt",content)
    \r\n
      content = eregi_replace("(javascript|vbscript)+","$1//",content)
    \r\n
      content = eregi_replace("(.location|location.|onload=|.cookie|alert|window.open|onmouse|onkey|onclick|view-source)+","//",content) '//자바스크립트 실행방지
    \r\n
     
    \r\n
      strip_tags2 = content
    \r\n
    End Function
    \r\n
     
    \r\n
     
    \r\n
    '사용예
    \r\n
    Dim allowtags, content
    \r\n
    allowtags = "br,a,img,b,font,div,center,embed"  ' 허용 ※ 태그 붙여서 연속으로, 공백 오류발생
    \r\n
     
    \r\n
    content = "<font color=red>허용하지 않은 태그</font>가<br />잘 <b>보이나요?</b><br /><script></script>"
    \r\n
    content = content & "<table><div align=center>아주 유용할꺼에요~</div><body><html><xmp><pre>"
    \r\n
     
    \r\n
    response.write "strip_tags1 결과<br />"& strip_tags1(content) &"<br /><br />"
    \r\n
    response.write "strip_tags2 결과<br />"& strip_tags2(content, allowtags)
    \r\n
    %>
    \r\n

    결과


    <소스보기>
    \r\n
    strip_tags1 결과
    \r\n
    허용하지 않은 태그가잘 보이나요?아주 유용할꺼에요~
    \r\n
     
    \r\n
    strip_tags2 결과
    \r\n
    <font color=red>허용하지 않은 태그</font>가<br />잘 <b>보이나요?</b><br /><script&gt</script&gt<table&gt<div align=center>아주 유용할꺼에요~</div><body><html&gt<xmp&gt<pre&gt


    참고자료
    http://flashcafe.org/3717 
    http://dualist.tistory.com/115
    \r\n

    \n
    [이 게시물은 관리자님에 의해 2013-11-18 21:29:50 11.H_BBS에서 이동 됨]
    [ 추가 정보 ... 더보기) ]
    뷰PDF 1,2



    office view

    관련자료

    댓글목록

    등록된 댓글이 없습니다.

    목록

    새창 작성 수정 목록 링크 Edit G카랜다 HDD HDD HDD 게시물 주소 복사




    Total 1,677 / 52 Page
    [ ■역방향프록시 응용) 시놀로지 도커 사용자 epg2xml/xmltv.xml 을 dsm 응용프로그램/역방향 프… ]

    ■ 시놀로지 도커 사용자 epg2xml/xmltv.xml 을 dsm 응용프로그램/역방향 프록시 규칙으로 웹상에서 epg 정보 출력 하기 ▶ ds…

    [ Ubuntu / Debian에서 새로운 고급 패키지 도구 (APT)를 사용하는 방법의 예2 ]

    14.Deb 패키지 설치.deb파일을 설치하려면다음과 같이 파일 이름을 인수로 사용하여 아래 명령을 실행하십시오.$ sudo apt deb at…

    [ Total Commander 버전 9.21a 다운로드 설치하여 U5PVR의 네트워크 드라이브 간단히 설정하… ] 댓글 2

    Total Commander 버전 9.21a 설치하여 U5PVR의 네트워크 드라이브 설정을 간단한 방법을 소개 드립니다저는 NEW 펌웨어 8/2…

    [ u5pvr 마우스 연결 감도 증대 및 무선랜-블루투스, 전파간섭 막으려면? (무선랜이 2.4GHZ만 있을 때… ]

    팁)u5pvr 마우스 연결 감도 증대 및 무선랜-블루투스, 전파간섭 막으려면? (무선랜이 2.4GHZ만 있을 때) 참조 자료미막스/tv-box …

    [ Windows x64 용 XPEnology 도구 ] 댓글 2

    Windows x64 용 XPEnology 도구https://xpenology.com/forum/topic/12422-xpenology-tool…

    [ 삼성노트북 R530으로 xpenology juns-mod-1.02b-ds3615extra-4.8 native… ] 댓글 3

    작업 완료)삼성노트북 R530 cpu 교체 작업 NT-R530-JA42S CPU 업그레이드와 조립 하기관리shimss11q2018-08-29 (…

    [ 해놀로지 부팅 juns loader native USB 설정 작업 하기 ] 댓글 4

    원도우 나 winpe 부팅 합니다Xpenology_Tool_V142.exe을 실행하여USB DEVICE VIEW 를 실행 합니다vendorID …

    [ Notepad++ 팁) /노트패드 에디터 줄단위 편집 > 빈줄제거 하기 ]

    Notepad++ 팁) /노트패드 에디터 줄단위 편집 > 빈줄제거 하기편집>Notepad++ 팁) /노트패드 에디터 줄단위 편집 &g…

    [ Docker 기본 디렉토리를 변경하는 방법 ]

    Docker 디렉토리를 변경하는 방법정보출처https://bobcares.com/blog/how-to-change-docker-directory…


    ♥간단_메모글♥


    최근글


    새댓글



    PHP 안에 HTML ☞ 홈페이지 화면갱신 시간은 ♨
    ▶ 2024-06-29 13:24:41

    오늘의 홈 현황


    • 현재 접속자♨ 557 명
    • 오늘 가입자※ 3 명
    • 어제 가입자※ 4 명
    • 주간 가입자※ 8 명
    • 오늘 방문자 1,630 명
    • 어제 방문자 2,007 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,402,792 명
    • 전체 게시물※ 8,663 개
    • 전체 댓글수※ 24,792 개
    • 전체 회원수 11,077 명

    QR코드


    ☞ QR코드 스캔은 kakao앱 자체 QR코드

    알림 0








    최신글↑