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);

 

호스트 추출
<?
preg_match("/^(http:\/\/)?([^\/]+)/i","http://www.naver.com/index.php",$matches);
$host = $matches[2];
echo$matches[0]."<br>";
echo$matches[1]."<br>";
echo$matches[2]."<br>";
?>

 

출처 : http://blog.naver.com/honglaeggo/90194126848

'웹프로그래밍 > php/asp' 카테고리의 다른 글

배열 검색 (최대값, 최소값, 키값)  (0) 2016.04.08
PHP 글자 짜르기  (0) 2015.03.20
PHP - 소수점 처리  (0) 2015.03.20
날짜/시간/요일  (0) 2015.03.19

+ Recent posts