위토즈 - 개발자프로그램판매공간

정보공유

[PHP] 정규식 제거 및 특정 태그 제거

정규식을 통한 개행 제거

$text = preg_replace('/\r\n|\r|\n/','',$text);


문자열 함수사용으로 개행 제거

$text = str_replace(array("\r\n","\r","\n"),'',$text); 

또는

$text = strtr($text,array("\r\n"=>'',"\r"=>'',"\n"=>''));


html 태그 제거

$content = preg_replace("(\<(/?[^\>]+)\>)", "", $content);


textarea 제거

$content = preg_replace("!<textarea(.*?)>!is","[textarea]",$content);

$content = preg_replace("!</textarea(.*?)>!is","[/textarea]",$content);


script 제거

$str=preg_replace("!<script(.*?)<\/script>!is","",$str);


iframe 제거

$str=preg_replace("!<iframe(.*?)<\/iframe>!is","",$str);


meta 제거

$str=preg_replace("!<meta(.*?)>!is","",$str);


style 태그 제거

$str=preg_replace("!<style(.*?)<\/style>!is","",$str);


&nbsp;를 공백으로 변환

$str=str_replace("&nbsp;"," ",$str);


연속된 공백 1개로

$str=preg_replace("/\s{2,}/"," ",$str);


태그안에 style= 속성 제거

$str=preg_replace("/ zzstyle=([^\"\']+) /"," ",$str); // style=border:0 따옴표가 없을때

$str=preg_replace("/ style=(\"|\')?([^\"\']+)(\"|\')?/","",$str); // style="border:0" 따옴표 있을때

 

태그안의 width=, height= 속성 제거

$str=preg_replace("/ width=(\"|\')?\d+(\"|\')?/","",$str);

$str=preg_replace("/ height=(\"|\')?\d+(\"|\')?/","",$str);


img 태그 추출 src 추출

preg_match("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$str,$result);

preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$str,$result);



특수문자 제거

$string = preg_replace("/[ #\&\+\-%@=\/\\\:;,\.'\"\^`~\_|\!\?\*$#<>()\[\]\{\}]/i", "", $string);


공백제거

$string = preg_replace('/ /', '', $string);

$string = preg_replace("/\s+/", "", $string);


반복 입력된 단어 제거

$string = preg_replace("/s(w+s)1/i", "$1", $string);


반복 입력된 부호 제거

$string = preg_replace("/.+/i", ".", $string);


영문자를 제외한 모든 문자 제거

$string = preg_replace("/[^A-Za-z]/", "", $string);


영문자와 공백문자(Space)를 제외한 모든 문자를 제거

$string = preg_replace("/[^A-Za-z|\x20]/", "", $string);


ASCII 범주 코드 영문+특수문자를 제외한 모든 문자를 제거

$string = preg_replace("/[^\x20-\x7e]/", "", $string);


img 태그 추출

preg_match_all("/<img[^>]*src=[\'\"]?([^>\'\"]+)[\'\"]?[^>]*>/", $img, $matchs);

print_r($matchs);

정보공유
Total 436건 1 페이지
번호 제목 글쓴이 날짜 조회
436 입금된 주문도 준비, 배송전까지는 취소할 수 있도록 하는 방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-10 412
435 CSS를 사용하여 4x4 형태의 갤러리 디자인 그리드 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-05 426
434 magnificPopup css 를 추가하여 popup 마다 다른 사이즈 로 띄우기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-16 971
433 magnificPopup 조건이 맞지 않으면 popup 띄우지 않기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-12 890
432 magnificPopup iframe 으로 form submit 하기 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-12 1014
431 mysql 사용자 함수 생성 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-09 793
430 html 로 된 svg 태그를 png 파일로 만들기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-08 978
429 prepare bind_param 쿼리구분 select * 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-14 1622
428 javascript 플랫폼 디바이스 확인 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-13 1708
427 stmt 등록 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-14 2022
426 prepare 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-16 1999
425 magnificPopup 으로 창을 호출 후 날짜 입력박스에 datepicker 실행되지 않는경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-13 1942
424 magnificPopup 파라미터 변수 값 ajax 타입으로 전송 방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-31 2002
423 jquery 로 text 필드와 file 첨부를 동시에. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-09 2135
422 파일 첨부 를 이미지버튼으로 대체한경우 첨부한 파일명 표시하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-09 2109