2008年9月11日 星期四

获取指定页面所有的url






新建网页 1




<?php



function getPageLink($url){



set_time_limit(0);



$html = file_get_contents($url);



preg_match_all("/<a(s*[^>]+s*)href=(["|']?)([^"'>s]+)(["|']?)/ies",$html,$out);



$arrLink = $out[3];



$arrUrl = parse_url($url);



if( isset($arrUrl['path']) && !empty($arrUrl['path']) ){



$dir = str_replace('','/',$dir = dirname($arrUrl['path']));

if( $dir == '/') $dir = '';

}



if(is_array($arrLink) && count($arrLink) > 0){



$arrLink = array_unique($arrLink);



foreach($arrLink as $key=>$val){



$val = strtolower($val);

if( preg_match('/^#*$/isU',$val)){



unset($arrLink[$key]);



}elseif(preg_match('/^//isU',$val)){



$arrLink[$key] = 'http://'.$arrUrl['host'].$val;



}elseif(preg_match('/^javascript/isU',$val)){



unset($arrLink[$key]);



}elseif(preg_match('/^mailto:/isU',$val)){



unset($arrLink[$key]);



}elseif( !preg_match('/^//isU',$val) && strpos($val,'http://') === FALSE){



$arrLink[$key] = 'http://'.$arrUrl['host'].$path.'/'.$val;



}



}

}



sort($arrLink);

return $arrLink;



}



print_r(getPageLink('http://lee.gs'));

?>