티스토리 뷰
데모 - http://demo.widgets.co.kr/?c=64/81/82
매뉴얼:
http://kr2.php.net/manual/kr/function.preg-replace.php
http://kr2.php.net/manual/kr/function.preg-match.php
http://kr2.php.net/manual/kr/function.str-replace.php
iframe 제거
$STRING=preg_replace("!<iframe(.*?)<\/iframe>!is","",$STRING);
script 제거
$STRING=preg_replace("!<script(.*?)<\/script>!is","",$STRING);
meta 제거
$STRING=preg_replace("!<meta(.*?)>!is","",$STRING);
style 태그 제거
$STRING=preg_replace("!<style(.*?)<\/style>!is","",$STRING);
를 공백으로 변환
$STRING=str_replace(" "," ",$STRING);
연속된 공백 1개로
$STRING=preg_replace("/\s{2,}/"," ",$STRING);
태그안에 style= 속성 제거
$STRING=preg_replace("/ style=([^\"\']+) /"," ",$STRING); // style=border:0... 따옴표가 없을때
$STRING=preg_replace("/ style=(\"|\')?([^\"\']+)(\"|\')?/","",$STRING); // style="border:0..." 따옴표 있을때
태그안의 width=, height= 속성 제거
$STRING=preg_replace("/ width=(\"|\')?\d+(\"|\')?/","",$STRING);
$STRING=preg_replace("/ height=(\"|\')?\d+(\"|\')?/","",$STRING);
img 태그 추출 src 추출
preg_match("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$STRING,$RESULT);
preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$STRING,$RESULT);
호스트 추출
<?
preg_match("/^(http:\/\/)?([^\/]+)/i","http://www.naver.com/index.html",$matches);
$host = $matches[2];
echo$matches[0]."<br>";
echo$matches[1]."<br>";
echo$matches[2]."<br>";
?>
http://www.naver.com
http://
www.naver.com
데모 - http://demo.widgets.co.kr/?c=64/81/82
매뉴얼:
http://kr2.php.net/manual/kr/function.preg-replace.php
http://kr2.php.net/manual/kr/function.preg-match.php
http://kr2.php.net/manual/kr/function.str-replace.php
iframe 제거
$STRING=preg_replace("!<iframe(.*?)<\/iframe>!is","",$STRING);
script 제거
$STRING=preg_replace("!<script(.*?)<\/script>!is","",$STRING);
meta 제거
$STRING=preg_replace("!<meta(.*?)>!is","",$STRING);
style 태그 제거
$STRING=preg_replace("!<style(.*?)<\/style>!is","",$STRING);
를 공백으로 변환
$STRING=str_replace(" "," ",$STRING);
연속된 공백 1개로
$STRING=preg_replace("/\s{2,}/"," ",$STRING);
태그안에 style= 속성 제거
$STRING=preg_replace("/ style=([^\"\']+) /"," ",$STRING); // style=border:0... 따옴표가 없을때
$STRING=preg_replace("/ style=(\"|\')?([^\"\']+)(\"|\')?/","",$STRING); // style="border:0..." 따옴표 있을때
태그안의 width=, height= 속성 제거
$STRING=preg_replace("/ width=(\"|\')?\d+(\"|\')?/","",$STRING);
$STRING=preg_replace("/ height=(\"|\')?\d+(\"|\')?/","",$STRING);
img 태그 추출 src 추출
preg_match("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$STRING,$RESULT);
preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$STRING,$RESULT);
호스트 추출
<?
preg_match("/^(http:\/\/)?([^\/]+)/i","http://www.naver.com/index.html",$matches);
$host = $matches[2];
echo$matches[0]."<br>";
echo$matches[1]."<br>";
echo$matches[2]."<br>";
?>
http://www.naver.com
http://
www.naver.com
데모 - http://demo.widgets.co.kr/?c=64/81/82
'PHP' 카테고리의 다른 글
KimsQ RB 사진 업로드 모듈 오류 해결 (0) | 2016.09.26 |
---|---|
IF 기본형 숫자, 날짜 비교 (0) | 2016.08.05 |
계좌이체시 사용되는 금융기관 목록과 공용코드 출력 (0) | 2016.08.04 |
고도몰 Mobile의 메인 아이콘 출력 소스 - 참고용 (0) | 2016.07.06 |
PHP - n달 뒤 날짜 구할때 익월 일수가 현월 일수보다 작을때 버그 해결 (1) | 2016.06.16 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- java
- JavaScript
- Android 개발
- 법정동코드
- apache
- 시도 이름
- 안드로이드 개발
- app
- 리눅스
- 안드로이드
- API
- 삭제한 파일 복원
- Linux
- rm으로 삭제
- MariaDB
- json
- LAPM
- MySQL
- 앱개발
- c++
- HTML
- delete
- Tomcat
- Non-Interactive
- r
- Android
- 파일삭제
- 시군구 이름
- install
- 지역고유코드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함