doncarluzzo Posted March 5, 2011 Share Posted March 5, 2011 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 More sharing options...
thescientist Posted March 5, 2011 Share Posted March 5, 2011 check this outhttp://www.w3schools.com/html/html_forms.asphttp://www.w3schools.com/php/php_forms.asphttp://www.w3schools.com/php/php_post.asp Link to comment Share on other sites More sharing options...
doncarluzzo Posted March 5, 2011 Author Share Posted March 5, 2011 check this outhttp://www.w3schools.com/html/html_forms.asphttp://www.w3schools.com/php/php_forms.asphttp://www.w3schools.com/php/php_post.asp 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 More sharing options...
birbal Posted March 5, 2011 Share Posted March 5, 2011 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. Link to comment Share on other sites More sharing options...
dsonesuk Posted March 5, 2011 Share Posted March 5, 2011 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 More sharing options...
thescientist Posted March 5, 2011 Share Posted March 5, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.