Right, so I've just created a script that will take a rapidshare link, convert it to an ip address and then add the unw ready to download in a download manager. This works fantastically for a single link, but I want it to work for multiple links. eg For each link, run the script and then list all the converted links at the end. Here's my current code: <? include 'config.php'; if ($_POST['links']) { $url = $_POST['links']; $page = file_get_contents($url); preg_match('/<form id="ff" action="(.*?)" method="post">/s', $page, $pre_link); $link = trim(html_entity_decode($pre_link[1])); function extract_numbers($string) { preg_match('/([\d]+)/', $string, $match); return $match[0]; } $done = extract_numbers($link); $x = gethostbyname('rs'.$done.'.rapidshare.com'); $iplink = preg_replace('/rapidshare.com/', $x, $url); $final = str_replace("http://" , "http://$un:$pw@" , $iplink); echo $final; } else { ?> <form method="post" action=""> <textarea name="links" cols="80" rows="20"></textarea> <br/> <input type="submit"/> </form> <? } ?> PHP: TIA
put each link on a new line and cut up the input from the textarea $lines = explode(" ", $_POST['links']); foreach($lines as $key => $val) { //do some validation if they're really links //run the function } PHP:
Thanks pig2cat! Only problem is now that the extract_numbers will only run once, I get this error: Fatal error: Cannot redeclare extract_numbers()
replace the function with this: if(!function_exists('extract_numbers')){ function extract_numbers($string) { preg_match('/([\d]+)/', $string, $match); return $match[0]; } } PHP:
Cheers, that got rid of the fatal error but it's still giving the same IP address for multiple links :/
Untested, but should work: <?php include 'config.php'; if ($_POST['links']) { if(!function_exists('extract_numbers')){ function extract_numbers($string) { preg_match('/([\d]+)/', $string, $match); return $match[0]; } } $url = $_POST['links']; $lines = str_replace(array("\r\n", "\r"), "\n", $url); $links = explode("\n", $lines); foreach($links as $link){ $page = file_get_contents($url); preg_match('/<form id="ff" action="(.*?)" method="post">/s', $page, $pre_link); $link = trim(html_entity_decode($pre_link[1])); $done = extract_numbers($link); $x = gethostbyname('rs'.$done.'.rapidshare.com'); $iplink = preg_replace('/rapidshare.com/', $x, $url); $final = str_replace("http://" , "http://$un:$pw@" , $iplink); echo $final."<br>"; } } else { ?> <form method="post" action=""> <textarea name="links" cols="80" rows="20"></textarea> <br/> <input type="submit"/> </form> <?php } ?> PHP: Just make sure all links have their own line.
<?php include 'config.php'; if ($_POST['links']) { if(!function_exists('extract_numbers')){ function extract_numbers($string) { preg_match('/([\d]+)/', $string, $match); return $match[0]; } } $url = $_POST['links']; $lines = str_replace(array("\r\n", "\r"), "\n", $url); $links = explode("\n", $lines); foreach($links as $url){ $page = file_get_contents($url); preg_match('/<form id="ff" action="(.*?)" method="post">/s', $page, $pre_link); $link = trim(html_entity_decode($pre_link[1])); $done = extract_numbers($link); $x = gethostbyname('rs'.$done.'.rapidshare.com'); $iplink = preg_replace('/rapidshare.com/', $x, $url); $final = str_replace("http://" , "http://$un:$pw@" , $iplink); echo $final."<br>"; } } else { ?> <form method="post" action=""> <textarea name="links" cols="80" rows="20"></textarea> <br/> <input type="submit"/> </form> <?php } ?> PHP: Try that, made alittle mistake in previous code.