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,683 / 1 Page
    [ smb연결) 시놀로지 네트워크 드라이브 totalcmd로 삼바 연결하기 ]

    1) 제어판 smb 서비스 활성화2) 사용자 권한 설정 >> 해당 아이디의 모든...모두 check 합니다.아래의 설정 진행 시 접속…

    [ u5pvr) U5 Air Remote 실행 OTA이후 BT 페어링모드 톱니바퀴 누룸 동작 안되어 페어링 … ] 댓글 8

    u5pvr) U5 Air Remote 실행 OTA이후 BT 페어링모드 톱니바퀴 누룸 동작 안되어 페어링 않됨을 조치를 공유 드립니다파일 이전 자…

    [ vmware iso 파일 booting이 되지 않네요 해결 방법 ]

    vmware REMIXOS... iso 파일 booting이 되지 않네요 아래와같이 부팅 되지 않습니다> UTRAIOS를 설치하여 부팅되는…

    [ 윈도우 최신버전에서 우툰을 설치 할수 있는 정보 및 xpenology DSM 6.1을 Windows… ]

    xpenology Windows 10이 설치된 DSM 6.1 및 bash로 빌드윈도우 최신버전에서 우툰을 설치 할수 있는 정보 입니다그리고 아래…

    [ 펌)도커]Synology NAS Docker 우분투 컨테이너 생성 ]

    도커]Synology NAS Docker 우분투 컨테이너 생성출처:http://naltaengi.tistory.com/41[날탱이가 되고픈 개발…

    [ Tvheadend 전자프로그램가이드 epg그래버모듈 web 구동 wget 다운로드하여 cat으로 불러오… ]

    Tvheadend 전자프로그램가이드 epg그래버모듈 web 구동 wget 다운로드하여 cat으로 불러오기왜) xmltv 만드는동안 안정되게 단계…

    [ 서버에 아파치 설치 후 php소스가 그대로 보일때.. ]

    서버에 아파치 설치 후 php소스가 그대로 보일때..최고관리자 서버 07,3712012.02.23 21:38먼저 확인해볼 사항들이 있다.*확장자…

    [ xbox one x 의 종료를 절전모드 설정 및 power off 의 소비 전력 ]

    xbox one x 의 종료를 절전모드 설정 및 power off 의 소비 전력전원 끄기 방법은 전원 종료 x전원키 길게 누르면 본체 끄기가 있…


    ♥간단_메모글♥


    최근글


    새댓글



    PHP 안에 HTML ☞ 홈페이지 화면갱신 시간은 ♨
    ▶ 2024-06-30 19:40:52

    오늘의 홈 현황


    • 현재 접속자♨ 562 명
    • 오늘 가입자※ 1 명
    • 어제 가입자※ 5 명
    • 주간 가입자※ 11 명
    • 오늘 방문자 1,525 명
    • 어제 방문자 2,101 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,404,788 명
    • 전체 게시물※ 8,669 개
    • 전체 댓글수※ 24,800 개
    • 전체 회원수 11,078 명

    QR코드


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

    알림 0








    최신글↑