Jump to content

form passed strings to array


doncarluzzo
 Share

Recommended Posts

Hello GuysHope I wont get too much critics for this. But even if my google skills aint that bad I did not get to what im looking for. First of im kinda noob to programming and php.I am trying to create a wgetform with html/php. The form contains:

Links:<textarea cols="50" rows="4" name="links"></textarea>

The content of $_POST["links"] i would like to pass into an array() which would be handeled with a foreach-loop.Just for testing I tried this:

$links=array($_POST["links"])foreach($links as $link){	echo $link;	echo "</br>";}

but I guess the most of you guys already know that this did not work out.So how would I pass the content (the links) into an array?regards

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks for your reply. I love w3schools because thats where I started learning php. Very great site!My Problem isnt the form, I got that part already
<body><form action="wget.php" method="post">Links:<textarea cols="50" rows="4" name="links"></textarea><input type="submit" value="download" /></form></body></html>

The problem is how to put the links i will be pasting into the textarea into a array?I want to turn $_POST["links"] into an array of links, how do I do this?

Link to comment
Share on other sites

you can write some links delimited by some character then you can do explodeif you write link1,link2,link3 textarea it will make an array of links.

Edited by birbal
Link to comment
Share on other sites

try this

<!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>Untitled Document</title> </head><body><p>Add link separeted by space </p> <p>Example:http://google.com http://google.co.uk</p><form action="wget.php" method="post">Links:<textarea cols="50" rows="4" name="links"></textarea><input type="submit" value="download" /></form><?php if(isset($_POST['links'])){$str = explode(" ", $_POST['links']);foreach($str as $link){echo $link.'<br />';}}?></body></html>

Link to comment
Share on other sites

The problem is how to put the links i will be pasting into the textarea into a array?I want to turn $_POST["links"] into an array of links, how do I do this?
I see. Well, as birbal suggested, you will have to have the links delimited while they are inputted into the text area, or use some sort of regex to separate them based on them having some sort of common prefix value (like www, or http://). One option might be to have multiple input values, one for each link, and you can use javascript to create a simple UI for the user where if they click a button, more inputs can appear for them to input more links.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...