Jump to content

Textarea to Hyperlinks's


danoli3

Recommended Posts

Hey I have been trying really hard to find some documentation on how to pass the values from a Textarea form back to the page to display the values as hyperlinks (if they are hyperlinks, but for this they are all hyperlinks)

 

For example:

 

Textarea:

http://www.google.com/download1.rar

http://www.google.com/download2.rar

http://www.google.com/download3.rar

http://www.google.com/download4.rar

 

Preview Button <-

 

Click and then page displays the links in the textarea in another place as links.

So you can use a program like download them all to 'download all rar links'.

 

Any idea?

 

How to separate line to line in the final equation and then I can attach the a hrefs...

 

help :)

 

Link to comment
https://forums.phpfreaks.com/topic/155953-textarea-to-hyperlinkss/
Share on other sites

<?php
// Our simulated text area. Note the newlines.
$data = "http://www.google.com\n
         http://www.yahoo.com\n
         http://www.ask.com\n
         http://www.aol.com";

// Seperate each line at it's newline character
$lines = explode("\n", $data);

// Show each one as a link
foreach($lines as $line)
{
    echo "<a href=\"{$line}\">{$line}</a></br>";
}
?>

AWesome! that works!

 

I set it up like this:

 

<?php
echo '<center>';
echo '<br><br><form action="'.$_SERVER['PHP_SELF'].'" method="post">';
echo '<textarea name="links" cols="60" rows="10">';
if(isset($_POST['links']))
{
  echo stripslashes($_POST['links']);
}
echo '</textarea><br>';
echo '<input type="submit" name="submit" value="Preview For Download Them All!"></center>';
if(isset($_POST['submit']))
{  
echo '<center>';
// Our simulated text area. Note the newlines.
$data = stripslashes($_POST['links']);
// Seperate each line at it's newline character
$lines = explode("\n", $data);
echo '<table bgcolor="#efefef" width="500">';
// Show each one as a link
foreach($lines as $line)
{
	echo "<tr><td>";
	echo "<a href=\"{$line}\">{$line}</a></br>";
	echo "</td></tr>";
}
  echo '</table>';
}
?>

 

Any improvements you think I could add?

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.