View Full Version : Resolved html post into php array

02-20-2012, 01:38 AM
Hello, I am using the following POST code
<form action="./test.php" Method="POST">
<textarea name="data[]" cols=40 rows=4></textarea>
<input type="submit" name="submit" value="submit" />
And I am using the following code in text.php
$array = $_POST['data'];

It works ok but I want to read every single row into an array as a new element.

Iam not sure whether it's a html related problem or php problem so I posted this here.

Looking for any kind of help :)

Mahdi Eftekhari
02-20-2012, 10:10 PM
As far as I know textarea does not return array. It sends the text as a whole. Then in php you can separate each line.
You need to use explode function in your php code.
html code will be (note the name):

<textarea name="data" cols=40 rows=4></textarea>
and php part will be:

$myArray = explode("\n",$_POST['data']);

If you need more information let me know
Mahdi Eftekhari

Mahdi Eftekhari
02-20-2012, 10:20 PM
Reference to explode function: http://php.net/manual/en/function.explode.php