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]+'",
"'&(quot|#34);'i", // HTML 엔티티 치환
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // php로 실행
$replace = array ("",
"",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
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=['\"]?([\?\&\=\/\.\_\: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=['\"]?([\?\&\=\/\.\_\: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;
}