Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    html post into php array

    Hello, I am using the following POST code
    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
    Code:
    <?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!
    Last edited by cloudd1; 02-20-2012 at 03:09 AM.

  • #2
    New Coder
    Join Date
    Feb 2012
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    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):
    Code:
    <textarea name="data" cols=40 rows=4></textarea>
    and php part will be:
    Code:
    $myArray = explode("\n",$_POST['data']);
    If you need more information let me know
    Thanks
    Mahdi Eftekhari
    Last edited by Mahdi Eftekhari; 02-20-2012 at 10:19 PM.

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    18
    Thanks
    0
    Thanked 1 Time in 1 Post
    Reference to explode function: http://php.net/manual/en/function.explode.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •