A

에디터로 작성한 게시물에서 특정태그없애기

· 17년 전 · 1304
<?php
$disable_tags = "table|td|tr|tbody"; //예제 금지 태그입니다

$tags = explode("|", $disabled_tags);
  for($i=0; $i < sizeof($tags); $i++) {
    $ntags[] = "@<".$tags[$i]."[^>]*?>@si";
    $ntags[] = "@</".$tags[$i].">@si";

  }
  $str = preg_replace($ntags,"", $str);
?>
정규식에는 문외한이라
걍 아는 php 지식으로 무식? 하게 만들어보았습니다.
만약 게시물이
"<table width=900 align=right>
<td width=100 bgcolor=#ffffff>
게시물 게시물 게시물......
ㄹㅇㄹㅇㄴㅁ러ㅏㅇ널찬ㅇ
</td><td width=1200>dfdfkdsfajdskfds
</td>
";
인 경우

"게시물 게시물 게시물...... ㄹㅇㄹㅇㄴㅁ러ㅏㅇ널찬ㅇdfdfkdsfajdskfds"

이렇게  금지태그 및 관련 attributes를 모두 없애줍니다


울나라 네티즌들은 나쁜 버릇이 하나 있지요?
그건 바로 남이 공들여 등록한 게시물을 걍 긁어다가
다른 사이트에 그대로 붙혀넣기 한다는겁니다.
물론 사이트관리자 입장에선 이러한 행동이 그다지 맘에 들지 않지요
혹여 붙혀넣기 도중 <table>이 끊긴다던지 하면 그 페이지에서는 전체 레이아웃이 영향을 받으니 ..그래서 아예 태그를 막는 분들도 계실테고..

P.S
정규식으로 고수님들이 다시 만들어 주심 감사하겠습니다

참 이건 제가 에디터로 작성한 HTML게시물을 보여줄때 쓰는건데요
다른 사이트에서 복사한 게시물에 달려오는 쓸데없는 태그 및 속성들
없애주는 함수입니다
<?php
function format_rte($str) { 
$search = array('@<script[^>]*?>.*?</script>@si',  //<script>태그없애기
                '@<style[^>]*?>.*?</style>@siU',    //<style>태그 없애기
                '@onload=(.*?)@si',  //<img 태그내에 삽입된 불필요한 속성 없애기
                '@onmouseover=(.*?)@si',
                '@onclick=(.*?)@si',
                '@onmousedown=(.*?)@si',
                '@onmouseout=(.*?)@si'
              );
$str = preg_replace($search,'', $str);
$str = eregi_replace("<IMG","<img border=\"0\" onLoad=\"imgFix(this)\" onClick=\"imgChkClick(this)\" onError=\"imgError(this)\"", $str);

return $str;
}
?>
//이미지 관련 자바스크립트
<script language="javascript">
//이미지 로딩에러시 이미지object 자체 안보이게 하기
function imgError(obj) {
    obj.style.display='none';
}

//이미지 폭이 특정 값 이상일때 폭 조정
function imgFix(obj) {
 var maxW = 600;  //조절한 특정 이미지 폭 값
 var img = document.createElement("img");
 img.src = obj.src;
 if(img.width > maxW) {
     obj.style.width = maxW;
     obj.style.height = img.height * (maxW/img.width);
     obj.style.cursor = 'url(images/magnify.cur),pointer';
 }
}
function imgChkClick(obj) {
 var maxW = 600;
 var img = document.createElement("img");
 img.src = obj.src;
 if(img.width > maxW) {
     picview(img.src,img.width,img.height);
 }
}

//이미지 새 창에서 보기
function picview(src,w,h) {

 var iw = screen.width - 16;
 var ih = screen.height - 68;
 var s = 0;
 var scroll = '';
if(w > iw) { w = iw; s += 1; }
if(h > ih) {
 h = ih; s += 1;
 if(w < iw) w += 20;
}
if(s > 0 ) { scroll = ",scrollbars=1"; }
var opt_mo = "top=5,left=5,width="+w+",status=no,height="+h+",resizable=1"+scroll;
NFW = window.open("","newWin",opt_mo);
NFW.focus();
var string = "<html>" +
            "<head><title>Photo</title></head>" +
            "<body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>" +
            "<a href='javascript:window.close()'><img src='" + src + "' border=0></a>" +
            "</body></html>";
NFW.document.open();
NFW.document.write(string);
NFW.document.close();
}
</script>
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
17년 전 조회 2,540
17년 전 조회 1,507
17년 전 조회 1,097
17년 전 조회 1,232
17년 전 조회 3,107
17년 전 조회 2,172
17년 전 조회 1,979
17년 전 조회 1,223
17년 전 조회 2,455
17년 전 조회 1,175
17년 전 조회 1,138
17년 전 조회 1,384
17년 전 조회 2,747
17년 전 조회 2,401
17년 전 조회 2,489
17년 전 조회 1,189
17년 전 조회 1,305
17년 전 조회 3,251
17년 전 조회 2,835
17년 전 조회 4,107
17년 전 조회 2,268
17년 전 조회 2,362
17년 전 조회 1,414
17년 전 조회 2,533
17년 전 조회 2,220
17년 전 조회 2,975
17년 전 조회 2,486
17년 전 조회 1,647
17년 전 조회 2,439
17년 전 조회 1,596
17년 전 조회 1,184
17년 전 조회 2,243
17년 전 조회 2,889
17년 전 조회 4,068
17년 전 조회 3,156
17년 전 조회 1,423
17년 전 조회 1,709
17년 전 조회 2,251
17년 전 조회 1,556
17년 전 조회 1,731
17년 전 조회 2,722
17년 전 조회 2,150
17년 전 조회 1,802
17년 전 조회 4,207
17년 전 조회 3,055
17년 전 조회 1,447
17년 전 조회 3,574
17년 전 조회 2,808
17년 전 조회 2,086
17년 전 조회 1,305
17년 전 조회 2,344
17년 전 조회 2,076
17년 전 조회 1,992
17년 전 조회 1,937
17년 전 조회 1,186
17년 전 조회 1,891
17년 전 조회 2,944
17년 전 조회 1,443
17년 전 조회 1,684
17년 전 조회 1,369
17년 전 조회 1,614
17년 전 조회 1,587
17년 전 조회 1,459
17년 전 조회 2,573
17년 전 조회 2,337
17년 전 조회 2,114
17년 전 조회 1,425
17년 전 조회 2,441
17년 전 조회 4,261
17년 전 조회 2,745
17년 전 조회 1,671
17년 전 조회 1,864
17년 전 조회 3,242
17년 전 조회 2,249
17년 전 조회 3,840
17년 전 조회 1,688
17년 전 조회 2,281
17년 전 조회 2,111
17년 전 조회 1,627
17년 전 조회 2,143
17년 전 조회 1,941
17년 전 조회 1,974
17년 전 조회 3,085
17년 전 조회 2,159
17년 전 조회 1,448
17년 전 조회 1,472
17년 전 조회 2,135
17년 전 조회 3,212
17년 전 조회 2,152
17년 전 조회 1,542
17년 전 조회 4,245
17년 전 조회 2,035
17년 전 조회 3,468
17년 전 조회 6,042
17년 전 조회 1,498
17년 전 조회 1,667
17년 전 조회 1,247
17년 전 조회 1,362
17년 전 조회 2,884
17년 전 조회 1,919
🐛 버그신고