Jump to content

Recommended Posts


<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];
    }


 

 

Link to comment
https://forums.phpfreaks.com/topic/239190-form-contents-put-into-an-array/
Share on other sites

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

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

$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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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