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,671 / 6 Page
    [ iptime 공유기 a6004ns URL서비스 usb_hdd 중간 폴더 숨기기하여 공개폴더로 이동 패스워드… ] 댓글 5

    iptime 공유기 a6004ns URL서비스 중간 폴더 숨기기하여 공개폴더로 이동 패스워드 만들기간단히 공유 web file 폴더를 만들어 상…

    [ 스팸대응) 메일 릴레이대응 구글링 관련자료 펌업)다른 사람이 내 이메일을 사용하고 있나요? 이메일 스푸핑에… ] 댓글 32

    다른 사람이 내 이메일을 사용하고 있나요? 이메일 스푸핑에 대해 알아보기\r\n\r\n내 계정에서 보낸 것처럼 보이는 메일이 반송되었단 메일을 …

    [ 스마트폰과 시놀로지 나스를 이용해서 CCTV로 사용하는법_사용기 ] 댓글 1

    무료 4000원 투자 하지 않고는 서버시작을 눌러야 하며 구글 화면에서 시놀로지 에서 아래와같이 설정해야 나옴ip:포트확인을 하고 설정( 192…

    [ Synology Assistant 한글 폰트 깨짐 arialuni.ttf 설치로 한글 해결하기. ] 댓글 3

    Synology Assistant 한글 폰트 깨짐 해결하기.출처:http://hobby.tw/430[최신 소식들...]arialuni.ttf한글…

    [ 헤놀로지 하드 HDD 늘리기 하드 갯수 추가하기 설정값 변경 / usb외장을 내장으로 사용 ] 댓글 3

    ===========================주) 하기 수정은 dsm 재설정 되서 초기 설치시 바랍니다.저는 기존 HDD 구성으로 DSM 재…

    [ Malscrmon 0.4 URL 모니터링 ]

    Malscrmon 0.4 URL 모니터링 - Hark의 이것저것 - 티스토리everyhark.tistory.com/1052016. 1. 14. …

    [ SKIPTV 채널정리를 2017년10월26자 정리 해 보았습니다. ] 댓글 19

    저의 최종 iptv 채널리스트 링크 참조 바랍니다IPTV 채널 시청을 위하여SKIPTV 채널정리를 2017년10월26자 정리 해 보았습니다.시청…

    [ u5pvr) linux 펌웨어 20171205 업데이트후 초기화 설정 진행 ] 댓글 1

    u5pvr)linux 펌웨어 업데이트후 초기화 설정 진행사용버전http://cafe.naver.com/mk802/24277- 조건 : linux…

    [ FAT32 간단하게 PartitionGuru_portable 이용 microsd USB FORMAT / 포멧… ] 댓글 1

    FAT32 간단하게 PartitionGuru_portable 이용 microsd USB FORMAT / 포멧 하기단일 파일 로 사용이 편리 합니…

    [ 참조)스마트에디터 모바일에서 사용하기 ]

    적용법]4.3버전까지 패치하신후에사이트/config.php 파일에서define('G5_IS_MOBILE_DHTML_USE', false);를 찾…

    [ ■ ★ u5pvr)tvheadend 의 epg 의 xmltv.xml 를 자동 스케줄러 만들어 사전에 정기적으… ] 댓글 56

    ■u5pvr)tvheadend 의 epg 의 xmltv.xml 를 자동 스케줄러 만들어 사전에 정기적으로 만들어 놓고 tvheadend epg그…

    [ TVHEADEND NZ 라디오 IPTV 설정 ]

    아래내용은 참조만하시고링크내용으로https://11q.kr/g5s/bbs/board.php?bo_table=s11&wr_id=5398참조…


    ♥간단_메모글♥


    최근글


    새댓글



    PHP 안에 HTML ☞ 홈페이지 화면갱신 시간은 ♨
    ▶ 2024-06-01 20:23:01

    오늘의 홈 현황


    • 현재 접속자♨ 533 명
    • 오늘 가입자※ 2 명
    • 어제 가입자※ 4 명
    • 주간 가입자※ 12 명
    • 오늘 방문자 1,890 명
    • 어제 방문자 1,415 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,353,036 명
    • 전체 게시물※ 8,611 개
    • 전체 댓글수※ 24,675 개
    • 전체 회원수 11,004 명

    QR코드


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

    알림 0








    최신글↑