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
| function get_link($string,$baseurl=""){
$url=array();
$urltexte=array();
$urlext=array();
$len=strlen($string);
$pos=-1;
$base=ereg_replace("(/$)|(/[^/]*\.[^/]*$)","",$baseurl)."/";
$nextbasepos=strpos($string,"<base");
while ((($pos=strpos($string,"<a",$pos+1))!==false) && (($pos2=strpos($string,'>',$pos+1))!==false) && (($pos3=strpos($string,"<",$pos2+1))!==false)){
$str=substr($string,$pos,$pos3-$pos+1);
while (($nextbasepos!==false) && ($nextbasepos < $pos)){
if ((($pos4=strpos($string,">",$nextbasepos+1))!==false)
&& ereg('href[ ]*=[ ]*"[ ]*(http://[^"]*)"',substr($string,$nextbasepos,$pos4-$nextbasepos+1),$arr)) $base=ereg_replace("(/$)|(/[^/]*\.[^/]*$)","",trim($arr[1]))."/";
$nextbasepos=$pos4 ? strpos($string,"<base",$pos4) : false;
}
$pos=$pos3;
if (ereg('href[^"]*"[ ]*([^"#][^"]*)"[^>]*>([^<]*)<',$str,$arr)){
$http=(substr(trim($arr[1]),0,7)==="http://");
array_push($url,($link=$http ? trim($arr[1]) : $base.ereg_replace("^/","",trim($arr[1]))));
array_push($urltexte,$arr[2]);
array_push($urlext,ereg("[^?#]*[^/?#]/[a-zA-Z0-9_.\-]+(\.[a-zA-Z0-9]+)(\?|#|$)",$link,$arr2) ? $arr2[1] : "");
}
}
return array($url,$urltexte,$urlext);
} |
Partager