Jump to content

[SOLVED] find similar links in a string and list them


Recommended Posts

How can I make a code that would find links from a string and list them like this:

 

Download from sample.com
http://sample.com/downloadlink1.rar.part1
http://sample.com/downloadlink1.rar.part2
http://sample.com/downloadlink1.rar.part3
http://sample.com/downloadlink1.rar.part4
http://sample.com/downloadlink1.rar.part5
http://sample.com/downloadlink1.rar.part5

Download from sample.com (2)
http://sample.com/downloadlink1mirror.rar.part1
http://sample.com/downloadlink1mirror.rar.part2
http://sample.com/downloadlink1mirror.rar.part3
http://sample.com/downloadlink1mirror.rar.part4
http://sample.com/downloadlink1mirror.rar.part5
http://sample.com/downloadlink1mirror.rar.part5

Download from sample1.com
http://sample1.com/downloadlink12.rar.part1
http://sample1.com/downloadlink12.rar.part2
http://sample1.com/downloadlink12.rar.part3
http://sample1.com/downloadlink12.rar.part4
http://sample1.com/downloadlink12.rar.part5
http://sample1.com/downloadlink12.rar.part6

Download from sample11.com
http://sample11.com/?ASDBK1
http://sample11.com/?DFASFD
http://sample11.com/?DSNMJKSDK

 

Lets say the string is:

$string = "http://sample.com/downloadlink1.rar.part1
http://sample.com/downloadlink1.rar.part2
http://sample.com/downloadlink1.rar.part3
http://sample.com/downloadlink1.rar.part4
http://sample.com/downloadlink1.rar.part5
http://sample.com/downloadlink1.rar.part5
http://sample.com/downloadlink1mirror.rar.part1
http://sample.com/downloadlink1mirror.rar.part2
http://sample.com/downloadlink1mirror.rar.part3
http://sample.com/downloadlink1mirror.rar.part4
http://sample.com/downloadlink1mirror.rar.part5
http://sample.com/downloadlink1mirror.rar.part5
http://sample1.com/downloadlink12.rar.part1
http://sample1.com/downloadlink12.rar.part2
http://sample1.com/downloadlink12.rar.part3
http://sample1.com/downloadlink12.rar.part4
http://sample1.com/downloadlink12.rar.part5
http://sample1.com/downloadlink12.rar.part6
http://sample11.com/?ASDBK1
http://sample11.com/?DFASFD
http://sample11.com/?DSNMJKSDK";

here i made this (i am board)

<?php
function get_domain ($url){ 
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',$url, $matches);
$host = $matches[1];

// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
return $matches[0];
}
$string = "http://sample.com/downloadlink1.rar.part1
http://sample.com/downloadlink1.rar.part2
http://sample.com/downloadlink1.rar.part3
http://sample.com/downloadlink1.rar.part4
http://sample.com/downloadlink1.rar.part5
http://sample.com/downloadlink1.rar.part5
http://sample.com/downloadlink1mirror.rar.part1
http://sample.com/downloadlink1mirror.rar.part2
http://sample.com/downloadlink1mirror.rar.part3
http://sample.com/downloadlink1mirror.rar.part4
http://sample.com/downloadlink1mirror.rar.part5
http://sample.com/downloadlink1mirror.rar.part5
http://sample1.com/downloadlink12.rar.part1
http://sample1.com/downloadlink12.rar.part2
http://sample1.com/downloadlink12.rar.part3
http://sample1.com/downloadlink12.rar.part4
http://sample1.com/downloadlink12.rar.part5
http://sample1.com/downloadlink12.rar.part6
http://sample11.com/?ASDBK1
http://sample11.com/?DFASFD
http://sample11.com/?DSNMJKSDK";
$links=explode("\n",$string);
foreach($links as $key => &$value){
$domain=get_domain($value);
$domains[$domain].=$value."\n";
}
foreach($domains as $key => &$value){
echo 'Download from '.$key."\n".$value."\n\n\n";
}

?>

 

Scott.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.