devWhiz Posted June 13, 2011 Share Posted June 13, 2011 <center> <form action="testing.php" method="post" enctype="multipart/form-data"> <p> <textarea rows="10" cols="50" name="testacct" wrap="physical">Enter Text...</textarea> <p><br> <input type="submit" name="submit" value="Submit" /> </form> </center> In the text area there will be information in this apple orange peach pear banana watermelon Thats just an example of the content that will be submitted, it needs to be put into an array like $Fruit[0] = apple and $Fruit[1] = orange then I would do for($x=0; $x!=count($Fruit); $x++) { echo $Fruit[$x][0]." ".$Fruit[$x][1]; } Quote Link to comment https://forums.phpfreaks.com/topic/239190-form-contents-put-into-an-array/ Share on other sites More sharing options...
mikesta707 Posted June 13, 2011 Share Posted June 13, 2011 Well normally you could just use explode with a space as a delimiter, but we are dealing with newlines as well as spaces here, so what I would do is replace all new lines with a space. then use a simple explode. for example //assume $str contains the info from your text area $newstr = str_replace("\n", " ", $str); $fruits = explode(" ", $str); Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/239190-form-contents-put-into-an-array/#findComment-1228906 Share on other sites More sharing options...
devWhiz Posted June 13, 2011 Author Share Posted June 13, 2011 thank you for the reply I have an issue <center> <form action="testing.php" method="post" enctype="multipart/form-data"> <p> <textarea rows="10" cols="50" name="testacct" wrap="physical">Enter Text...</textarea> <p><br> <input type="submit" name="submit" value="Submit" /> </form> </center> <?php $LoginInput = $_POST['testacct']; $newstr = str_replace("\n", " ", $LoginInput); $fruits = explode(" ", $newstr); for($cwb=0; $cwb!=count($fruits); $cwb++) { echo "<center>".$fruits[$cwb][0]." ".$fruits[$cwb][1]."</center><br>"; } ?> That is the code I used, The input that was in the text area was as follows apple peach orange pear apple banana When I click submit, this is the output a p p e o r p e a p b a any idea on what could be causing this issue? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/239190-form-contents-put-into-an-array/#findComment-1228913 Share on other sites More sharing options...
Pikachu2000 Posted June 13, 2011 Share Posted June 13, 2011 $fruits[0] is the string 'apple' and what is happening is $fruits[0][0] is 'a' and $fruits[0][1] is 'p'. The problem is the arrangement of your array. After the $fruits = explode( . . ., print_r() the $fruits array so you can see how you'll need to loop through it to get the results you're after. Quote Link to comment https://forums.phpfreaks.com/topic/239190-form-contents-put-into-an-array/#findComment-1228915 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.