This is a simple function to extract link from a specific page/URL :
function extract_url($main_url){$cek_url = parse_url($main_url);
$prefix_url = $cek_url[‘scheme’].’://’.$cek_url[‘host’];
$f = fopen($main_url,”r”);
$inputStream = fread($f,65535);
fclose($f);
if (preg_match_all(“/(.*?)</a>/i”,$inputStream,$matches)) {
foreach($matches[1] as $link){
if(!eregi(‘mailto:|javascript:|ymsgr:’,$link)){
if(eregi(“https://”,$link)){
$url = $link;
}
else{
$url = $prefix_url.$link;
}
if(eregi(‘PHPSESSID’,$url)){
$url = explode(“PHPSESSID”,$url);
$url = substr($url[0],0,-1);
}
$output[] = $url;
}
}
}
return array_unique($output);
}
?>
And here is sample how to use the function:
$start = time();
print_r(extract_url(“https://dev.sandalian.com/”));
$end = time();echo ‘done in ‘.($end-$start).’ second’;
?>
This script only working when remote_url are allowed. Otherwise you will need to use CURL.
Jamal Soueidan
Looks goods, but it can be more complicated then that 🙂
When its comes to extract url from the whole domain (subpages) etc. 🙂
Rizky
tujuannya buat apa? mendingan bikin email address extractor pak.
Sandal
@ Jamal Soueidan
Yupe, but this is the basic function to do all that stuffs.
@ Rizky
Yeh, kan dimulai dari ini dulu Pak, biar bisa ngikutin link baru di extract alamat emailnya
Mbah Darmo
@ Rizky
Yeh, kan dimulai dari ini dulu Pak, biar bisa ngikutin link baru di extract alamat emailnya
Please Translate it to english 😀
Funkshit
why dont use CURL since u know that FOPEN is more possible to disable
*maaf, bahasa inggris saya pathing pechothot
Sandal
@pangsit
since I was too lazy to write CURL script :p
web design
do you know how can i extract all URLS from string??