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,675 / 60 Page
    [ [팁] MySQL 테이블 에러 해결 방법 ]

    \r\n[팁] MySQL 테이블 에러 해결 방\r\n\r\n\r\n요며칠 개인적인 용도로 운영중인 서버가 말썽을 부렸습니다.바쁘다는 핑계로 서버…

    [ 자작나스,pc소음줄이기) 케이스/팬 소음 줄이기및팬 속도 조절 / 볼륨저항 VR저항 500옴 입니다. ] 댓글 2

    자작나스,pc소음줄이기) 케이스/팬 소음 줄이기및팬 속도 조절 / 볼륨저항 VR저항 500옴 참고 사항1) 케이스 팬의 소음을 팬의 속도를 줄이…

    [ 아미나 모바일 amna mobile 글 수정 무조건 가능하게 하기 ]

    \r\n-----파일 1수정-----------\r\n//m/skin/view.skin.amina.php #8 아래 //처리 수정으로 모바일 수…

    [ plus_dtd20111212utf8 ]

    http://zeronara.net/bbs/board.php?bo_table=zenaplus&wr_id=1760\r\nplus_dtd20…

    [ IE6에서 레이어 고정시키기 핵. Fixed Layer Hack for IE6 ... ]

    . \r\n\r\nIE6에서 레이어 고정시키기 핵. Fixed Layer Hack for IE6 ...‎ - 2007년 9월 7일 \r\n\r\…

    [ 모바일용 스킨 ]

    .\r\n.\r\nShims HomePage\r\n[https://11q.kr 홈피] \r\n\r\n\r\nhttp://www.mozoki.co…

    [ new.php를 홈페이지 메인 index에 추가시 글 링크가 bbs가 빠지는것 채택됨 ] 댓글 1

    방법은\r\nnew.php를 new2.php로 변경 수정 하는 방법입니다\r\n\r\n.new.php를 홈페이지 메인 index에 추가시 글링크…

    [ G4DTD -> G4 디비변환 (UTF-8 only) ]

    목록글쓰기G4DTD -> G4 디비변환 (UTF-8 only) 모조키작성일시 2013.05.09 09:28:16조회 45 댓글 1 첨부파일…

    [ fat HDD 형식 ntfs 형식으로 변환하기 ]

    FAT hdd현식은 4gIGA 이하로 COPY 가능핮니가\r\n4GIGS 이상 5GIGA이상 카피 불가능한 파일 NTSC로 HDD형…

    [ HTML 트루 컬러 차트 폰트색상 _마우스카피 가능표 ]

    HTML 트루 컬러 차트 폰트색상 _마우스카피 가능표\r\n\r\nhttp://translate.google.co.kr/translate?hl=…

    [ 파일삭제)설치순서사진_DS3617xs 6.1 Jun's Mod V1.02a2-alpha_11q.kr_v2_s… ] 댓글 23

    최종 파일 사용하세요성공up)DSM6.1.1에서 DSM6.1.2로 juns-mod-1.02b-ds3615 이용 업데이트 LAN카드 정상 연결 .…

    [ 아미나 모바일에서 글 수정시 html 태그 없애고 저장 하기 ]

    .림스 모바일 부분 내용 참조 추가부분 \r\n. Shims HomePage [https://11q.kr 홈피] .\r\n\r\n\r\n\r\n…

    [ [림스업] 배추 게시판 림스모바일 사용시 삭제 않되는 문제 추가 m/bbs/delete.php에 스킨 경로… ]

    // 배추 게시판 림스모바일 사용시 삭제 않되는 문제 추가 m/bbs/delete.php에 스킨 경로 #3추가시작// 스킨경로 추가 내용$boa…

    [ g4s를g5로 변경하기 내용및 홈피의 data폴더의 dbconfig.php가 define('G5_TABLE_… ]

    방법 1) 신규 설치 방법1.기본적으로 신규 폴더에 g5를설치한다 ( phpMyAdmin 신규 data를 만들어 설치 / 나중에 기존 mysql…


    ♥간단_메모글♥


    최근글


    새댓글



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

    오늘의 홈 현황


    • 현재 접속자♨ 847 명
    • 오늘 가입자※ 0 명
    • 어제 가입자※ 2 명
    • 주간 가입자※ 8 명
    • 오늘 방문자 1,939 명
    • 어제 방문자 2,051 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,396,546 명
    • 전체 게시물※ 8,655 개
    • 전체 댓글수※ 24,772 개
    • 전체 회원수 11,068 명

    QR코드


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

    알림 0








    최신글↑