Jump to content

[SOLVED] Link extractor from textarea, NOT a website


deed02392

Recommended Posts

I want to extract rapidshare.com links from a bunch of text that gets submitted from a textarea.

 

http://pastebin.com/m23119236

 

So far I've made it so it removes the extension .html so my download manager can download the file and not the page rapidshare redirects me to. I read quite a bit into it and I think the key is regexp function, but I'm not sure how to implement it so that it ONLY will print the result including the link http://rapidshare.com/* or http://www.rapidshare.com/*.

 

Thanks in advanced!

give me an example of the input a user can/will submit, so I have an idea how to go about doing this.  do they just insert the link, or a whole load of data?

 

http://www.georgehafiz.co.uk/linkfilter.php

 

In here, you would post a big bunch of text, for example:

 

Backup 1:

http://rapidshare.com/files/#####
http://rapidshare.com/files/#####
http://rapidshare.com/files/#####
http://rapidshare.com/files/#####
http://rapidshare.com/files/#####

Backup 2: http://rapidshare.com/files/##### http://rapidshare.com/files/#####
http://rapidshare.com/files/#####http://rapidshare.com/files/#####

 

This would all get cleaned up to just show the rapidshare links on line breaks. So far my script just removes any .html extension to the file so I can download directly the file from the page, instead of going to the html page where it then pops up... I'd now also like to be able to remove anything that ISN'T a rapidshare link, and the echo them on lines. I was thinking something like explode() and then removing any entry in the array that wasn't a link but for that I need regexp and I have no idea how to do this, it's a bit too complicated. If you could give me a quick example I will be able to pick it apart and learn it, that's the way I learn  :-\

 

this should do it for you:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rapidshare Link Filter</title>
<?php

//vars
$oldText = $_POST['tofilter'];
$array = explode("\n", $oldText);
$result = "";
foreach ($array as $value){
if (strstr($value, "http")){
	$result .= str_replace(".html", "", $value)."<br />";
}
}
?>

</head>

<body>


<?php
if ($oldText) {

echo "Filtered result:<br />";
echo $result;
echo "<br />";
echo "<a href='javascript:history.go(-1)'>Go again</a>";

}
else {
echo '<form method="post" action="linkfilter.php">
  <b>Enter data to filter:</b><br />
  <textarea name="tofilter" wrap="virtual" rows="20" cols="100">';
$oldText;
echo '</textarea>
  <br /><input type="submit" name="submit" value="Submit" />
</form>
<br />
';
}
?>

</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.