...

View Full Version : Resolved html post into php array



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

print_r($array);
?>
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 :)
Thanks!

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
Thanks
Mahdi Eftekhari

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum