그러냐

strip_tags2() 본문

php

strip_tags2()

관절분리 2016. 1. 25. 14:26
반응형

function check_image($url, $timeout = 1)
{
$url_stuff = parse_url($url);
$host_name = $url_stuff[host];
$fp = fsockopen($host_name, 80, $errno, $errstr, 1);
if (!$fp) {
return 0;
} else {
socket_set_timeout($fp, $timeout);

$out = "GET $url HTTP/1.1\r\n";
$out .= "Host: $host_name\r\n";
$out .= "Connection: Close\r\n\r\n";

if (fputs($fp, $out)) {
$res = fread($fp, 1024);
if (stristr($res, "Content-Type: image")) {
return 1;
}
}

fclose($fp);
}
return 0;
}




function strip_tags2($data){
//echo $data;
$search = array ("'<script[^>]*?>.*?</script>'si", // 자바 스크립트 제거
"'<[\/\!]*?[^<>]*?>'si", // HTML 태그 제거
"'<\!\-\-(.*)?\-\->'si", //주석제거
"'([\r\n])[\s]+'",
"'&amp;(quot|#34);'i", // HTML 엔티티 치환
"'&amp;(amp|#38);'i",
"'&amp;(lt|#60);'i",
"'&amp;(gt|#62);'i",
"'&amp;(nbsp|#160);'i",
"'&amp;(iexcl|#161);'i",
"'&amp;(cent|#162);'i",
"'&amp;(pound|#163);'i",
"'&amp;(copy|#169);'i",
"'&amp;#(\d+);'e"); // php로 실행

$replace = array ("",
"",
"",
"\\1",
"\"",
"&amp;",
"&lt;",
"&gt;",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");

return preg_replace($search,$replace,$data);
}//end function



function extract_image_src($data){

preg_match_all("/src=['\"]?([\?\&amp;\=\/\.\_\:a-z0-9]+)['\"\s]?/i",$data,$out,PREG_SET_ORDER);//파라미터 사용할 경우

foreach($out as $key=>$val){
$link = $val[1];

if( ereg("\.gif|\.jpg|\.png",$link) ){
if( ereg("http://",$link ) ){
$src = $link;
}else if( ereg("^..\/",$link) ){
continue;
//$src = "http://".$_SERVER['HTTP_HOST']."/".substr($link,3);
} elseif ( ereg("^\/",$link) ) {
continue;
//$src = "http://".$_SERVER['HTTP_HOST']."/".substr($link,2);
} else {
continue;
//$src = "http://".$_SERVER['HTTP_HOST']."/".$link;
}

return $src;
break;
}


}//end of foreach
return;
}


function extract_swflash_src($data){

preg_match_all("/src=['\"]?([\?\&amp;\=\/\.\_\:a-z0-9]+)['\"\s]?/i",$data,$out,PREG_SET_ORDER);//파라미터 사용할 경우

foreach($out as $key=>$val){
$link = $val[1];

if( ereg("\.swf",$link) ){
if( ereg("http://",$link ) ){
$src = $link;
}else if( ereg("^..\/",$link) ){
$src = "http://".$_SERVER['HTTP_HOST']."/".substr($link,3);
} elseif ( ereg("^\/",$link) ) {
$src = "http://".$_SERVER['HTTP_HOST']."/".substr($link,2);
} else {
$src = "http://".$_SERVER['HTTP_HOST']."/".$link;
}

return $src;
break;
}


}//end of foreach
return;
}

반응형