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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| function get_link($string,$inibase1=""){
$url=array();
$urltexte=array();
$urlext=array();
$string2=strtolower($string." .");
$len=strlen($string);
$pos=-1;
$debut=ereg("^(#|\?)",$inibase1) ? "" : strtok($inibase1,"#?");
$file=ereg("[^/]/[a-zA-Z0-9_.\-]+(\.[a-zA-Z0-9]+)$",$debut);
$inibase1=eregi("^http://[^/]*",$debut) ? $debut.($file ? "" : "/").substr($inibase1,strlen($debut)) : $inibase1;
$inibase2=eregi_replace("^(http://.+)/[^/]*$","\\1",
eregi_replace("^http://[/]*","http://",$debut))."/";
$inibase3=eregi_replace("^(http://[^/]+)/.*","\\1",$inibase2)."/";
$base1=$inibase1;$base2=$inibase2;$base3=$inibase3;
$nextbasepos=strpos($string2,"<base");
while ((($pos=strpos($string2,"<a ",$pos+1))!==false) && (($pos2=strpos($string2,'>',$pos+1))!==false) && (($pos3=strpos($string2,"<",$pos2+1))!==false)){
$str=substr($string,$pos,$pos3-$pos+1);
while (($nextbasepos!==false) && ($nextbasepos < $pos)){
if ((($pos4=strpos($string2,">",$nextbasepos+1))!==false)
&& eregi('href[ ]*=[ ]*"[ ]*(http:[^"]*)"',substr($string2,$nextbasepos,$pos4-$nextbasepos+1),$arr)){
$basex=trim($arr[1]); $base1=((substr($basex,0,7)==="http://") ? $basex : ((substr($basex,0,6)==="http:/") ? $inibase3.substr($basex,6) : $inibase2.substr($basex,5)));
$debut=ereg("^(#|\?)",$base1) ? "" : strtok($base1,"#?");
$file=ereg("[^/]/[a-zA-Z0-9_.\-]+(\.[a-zA-Z0-9]+)$",$debut);
$base1=eregi("^http://[^/]*",$debut) ? $debut.($file ? "" : "/").substr($base1,strlen($debut)) : $base1;
$base2=eregi_replace("^(http://.+)/[^/]*$","\\1",
eregi_replace("^http://[/]*","http://",$debut))."/";
$base3=eregi_replace("^(http://[^/]+)/.*","\\1",$base2)."/";
}
$nextbasepos=$pos4 ? strpos($string2,"<base",$pos4) : false;
}
$pos=$pos3;
if (eregi('href[^"]*"[ ]*([^"]*)"[^>]*>([^<]*)<',$str,$arr)){
$http=(strtolower(substr(trim($arr[1]),0,7))==="http://");
$root=(substr(trim($arr[1]),0,1)==="/");
$self= !trim($arr[1]) || (substr(trim($arr[1]),0,1)==="#");
array_push($url,($link=($http ? trim($arr[1]) : ($self ? strtok($base1,'#').trim($arr[1]) : ($root ? $base3.substr(trim($arr[1]),1) : $base2.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