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,684 / 55 Page
    [ 펌자료)리다이렉션(페이지 이동)의 3가지 방법, location.href ] 댓글 1

    리다이렉션(페이지 이동)의 3가지 방법, location.href서방님0건68회http://xn--qj1br0pu4d.kr/bbs/board.p…

    [ 네트워크 연결 이더넷 브리지 연결 설정 ]

    네트워크 연결 이더넷 브리지 연결 설정◎ ■ ▶ ☞ ♠ 정보찾아 공유 드리며 출처는 링크 참조 바랍니다. https://11q.kr ♠

    [ CoreElec - entware 설치 linux debian 작업 ] 댓글 1

    CoreElec - entwarehttps://tvch.tistory.com/Entware 란 무엇이며 설치 / 제거 방법은 무엇입니까?핵심ad…

    [ 펌정보)안드로이드 TV 박스 구매 필수 정보 정리 및 활용 종합 가이드 ]

    펌정보)안드로이드 TV 박스 구매 필수 정보 정리 및 활용 종합 가이드https://cafe.naver.com/mk802/34139■ ▶ ☞ ♠…

    [ 참조)샤오미 미박스(Mi Box) 글로벌롬(오레오) 올리기 및 교체 작업 필요 없음 ]

    참조)샤오미 미박스(Mi Box) 글로벌롬(오레오) 올리기 및 교체 작업 필요 없음니다MiBox3-EddyLab에디션에서 구입한 제품의 정보 입…

    [ iptime 공유기의 Plug-in APP 설치된 아파치 동작이 포트문제로 접속 공유기 아파치서버가 동작이 … ]

    iptime 공유기의 Plug-in APP 설치된 아파치 동작이 포트문제로 접속 공유기 아파치서버가 동작이 않될때 다른 임의 포트로 지정후 아파…

    [ 성공)공유기 외부 아이피 변경시 텔레그램으로 메세지 받기 ] 댓글 2

    외부 아이피 변경시 텔레그램으로 메세지 받기성공 했습니다zelits.tistory.com의 자료 입니다-----------------------…

    [ nano edit 에디터 설정 윈도우 편집기로 변경 명령 ] 댓글 5

    nano edit 에디터 설정 윈도우 편집기로 변경 명령 nano ~/.nanorc시놀로지 와 coreelec 의 조건입니다#nano ~/.na…

    [ Coreelec 의 Docker 설치 와 부팅 시간 미 사용시 조건 ]

    Coreelec 의 Docker 설치 와 부팅 시간설치후 iptv 전용 TV 자동실행 시간kodi 단독으로 docker 사용않함 조건시 부팅 -…

    [ nas 종료 및 재부팅이 작동하지 않습니다 ] 댓글 1

    안녕하세요,나를 위해 종료 및 재부팅이 작동하지 않습니다.지금은 종료를 시작할 때 약 5 분 정도 기다렸다가전원을 끊습니다.내 사양은 다음과 같…

    [ 리눅스(Linux) 포트 열기, 방화벽 설정해제 등 ]

    리눅스(Linux) 포트 열기, 방화벽 설정해제 등작성자v-eng작성일2016-09-05 09:47조회45022http://www.veng.co…

    [ nas 파일 pc다운로드 최상의 방법 ]

    pc에서 나스에 여러가지 접속 사용중입니다이중에서 nas의 파일을 pc 로 복사 하여파일 일괄 수정후 다시 nas로 복사 하고자 합니다이때 파일…

    [ Reboot to LibreELEC apk ]

    Reboot to LibreELEC apk■ ▶ ☞ 정보찾아 공유 드리며 출처는 링크 참조 바랍니다 ♠ . ☞ 본자료는 https://11q.k…

    [ Rsync 란 ? 복사 백업 tool 사용방법 ]

    Rsync 란 ? 복사 백업 tool 사용방법Rsync(Remoe Sync)는 원격에 있는 파일과 디렉토리를 복사하고 동기화 하기 위해서 사용하…

    [ 펌정보)SSL 적용 후 무조건 https로 접속되게 하는 방법 ]

    SSL 적용 후 무조건 https로 접속되게 하는 방법이학권2018.07.11 14:22:35조회10,506댓글22검색목록목록글쓰기안녕하세요! …


    ♥간단_메모글♥


    최근글


    새댓글



    PHP 안에 HTML ☞ 홈페이지 화면갱신 시간은 ♨
    ▶ 2024-07-05 14:37:58

    오늘의 홈 현황


    • 현재 접속자♨ 644 명
    • 오늘 가입자※ 2 명
    • 어제 가입자※ 8 명
    • 주간 가입자※ 17 명
    • 오늘 방문자 1,510 명
    • 어제 방문자 2,205 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,415,013 명
    • 전체 게시물※ 8,677 개
    • 전체 댓글수※ 24,834 개
    • 전체 회원수 11,091 명

    QR코드


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

    알림 0








    최신글↑