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 / 83 Page
    [ 성공/실사례)헤놀로지에서 시놀로지 자체 외부 액세스 ddns 및 quick connect 접속가능하게 s… ] 댓글 3

    (성공/실사례)헤놀로지에서 시놀로지 자체 외부 액세스 ddns 및 quick connect 접속가능하게 sn/mac 변경 하기링크2에 모든자료 …

    [ 펌업)EPG XML 윈도우용 프로그램 및 사용기_작업실패 ] 댓글 5

    펌업)EPG XML 윈도우용 프로그램 및 사용기너무나 간편한 epg파일을 만드는 유용한 프로그램입니다저는 실패 했습니다-----------실패 …

    [ 성공)시놀로지 나스에 Tvheadend 설치및root권한 없어진것 재설치 문제 해결및 iptv.m3u 설정… ] 댓글 32

    SynologyDSM611–Tvheadend설치하기성공)시놀로지 나스에 Tvheadend 설치및root권한 없어진것 재설치 문제 해결및 iptv…

    [ 기가바이트 메인보드 내장 인텔 랜카드 I219, Windows Server 2012 R2 2016 드라이버… ] 댓글 9

    기가바이트 메인보드 내장 인텔 랜카드 I219, Windows Server 2012 R2 2016 버전 드라이버 설치 _인식 설치하기기입니다기가…

    [ 펌) 헤놀로지 새로운 시리얼과 MAC주소 생성기(test전) ] 댓글 56

    헤놀로지새로운 시리얼과 MAC주소 생성기https://redmilk.co.kr/archives/4883디랙토리만들어 압축해제후1)파일관리자 실행…

    [ 펌자료)tvheadend 설치법 링크모음 ] 댓글 3

    xpenology 5.0 에 tvheadend 설치법 링크모음을http://www.ppomppu.co.kr/zboard/view.php?id=n…

    [ 게시판글 공유용 글주소복사 /새창으로보기/ 글수정 메뉴 버튼 상단 메뉴 추가 ] 댓글 1

    빨강모자님의 조언에게시판글 공유용 글주소복사 /새창으로보기/ 글수정 메뉴 버튼 상단 메뉴 추가 합니다파일 :w:\g5s\skin\board\Ba…

    [ showdown 다운예약 추가) showdown 으로 드라마 vod 다운로드 설정하기 ]

    showdown다운예약 추가) showdown 으로 드라마 vod 다운로드 설정하기showdown 의 기본 동작에 관련 패키지 동작설정과 드라마…

    [ 추천)구글 TV 플레이어 마켓에서 iptv 시청 플레이 녹화가능하며 타임쉬프트 가능한 progtv.apk … ] 댓글 10

    구글 TV 플레이어 마켓에서 iptv 시청 플레이 녹화가능하며 타임쉬프트 가능한 progtv.apk 추천한글화 버전 파일https://11q.k…

    [ 우분투)18.04 에 tvheadend 설치 windows 10 vmware workstation 15 파… ] 댓글 30

    우분투 18.04 에 tvheadend 설치windows 10 vmware workstation 15 입니다헤놀로지는 트랜스코딩을 못해 사용불가…

    [ 아미나 스킨 Basic-Board2_0_pdf_viewer_shimss 첨부된 pdf_show파일 viewe… ] 댓글 5

    먼저 감사 드립니다============아미나 스킨 Basic-Board2_0_pdf_viewer_첨부된 pdf_show파일 viewer/뷰어 …


    ♥간단_메모글♥


    최근글


    새댓글



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

    오늘의 홈 현황


    • 현재 접속자♨ 656 명
    • 오늘 가입자※ 0 명
    • 어제 가입자※ 8 명
    • 주간 가입자※ 17 명
    • 오늘 방문자 1,001 명
    • 어제 방문자 2,205 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,414,504 명
    • 전체 게시물※ 8,677 개
    • 전체 댓글수※ 24,827 개
    • 전체 회원수 11,089 명

    QR코드


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

    알림 0








    최신글↑