mysterbx Posted February 6, 2008 Share Posted February 6, 2008 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"; Quote Link to comment https://forums.phpfreaks.com/topic/89697-solved-find-similar-links-in-a-string-and-list-them/ Share on other sites More sharing options...
aschk Posted February 6, 2008 Share Posted February 6, 2008 I'm sure one of the regex guys will be able to help you do this. e.g. (this is not the actual answer). $regex = '/(domain here)(link here)/'; preg_match_all($regex,$str,$matches); print_r($matches); Quote Link to comment https://forums.phpfreaks.com/topic/89697-solved-find-similar-links-in-a-string-and-list-them/#findComment-459622 Share on other sites More sharing options...
ratcateme Posted February 6, 2008 Share Posted February 6, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89697-solved-find-similar-links-in-a-string-and-list-them/#findComment-459624 Share on other sites More sharing options...
mysterbx Posted February 6, 2008 Author Share Posted February 6, 2008 everything works great! thanks for the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/89697-solved-find-similar-links-in-a-string-and-list-them/#findComment-459735 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.