יש פונקצייה שנכתבה ע"י The AcE :
PHP קוד:
function getLinks ($file) {
$ur=parse_url($file); #parsh the URL
$data=file_get_contents($file); #get the file from the server
$regex="/<a.*href=[\"']?([^\"' >]+)[\"' >](.*)<\/a>/imsU";
preg_match_all($regex,$data,$matches,PREG_SET_ORDE R);
$_ins=array(); $_outs=array();
$_ins[]=trim($ur['path'],"/");
foreach ($matches as $match) {
$purl=parse_url($match[1]);
if (( #check if it is an inner link
($purl['host'] == $ur['host'] and $purl['scheme'] == 'http')
or (!$purl['host'] and !$purl['scheme'])) #check if has host (for when href is: 'javascript' then scheme is 'javascript' and no host set)
and !in_array(trim($purl['path'],"/"),$_ins) #check if not in our array, we don't need duplicated addresses
) {
$ins[]=array('text'=>$match[2],'href'=>trim($purl['path'],"/"));
$_ins[]=trim($purl['path'],"/");
continue;
} elseif (
$purl['host'] != $ur['host'] #check that it is actually an outgoing link
and !in_array(ltrim($match[1],"/"),$_outs) #check if not in our array to avoid duplicated links
and $purl['scheme'] == "http" #get only the http links
) {
echo "Putting in outs.\n";
$outs[]=array('text'=>$match[2],'href'=>ltrim($match[1],"/"));
$_outs[]=ltrim($match[1],"/");
continue;
}
}
return array('outs'=>$outs,'ins'=>$ins);
}
הפונקצייה מחזירה פלט בצורה של קישורים נכנסים \ יוצאים מהדף, כמובן שכל הקרדיט הולך אליו כן?