Jump to content

Recommended Posts

Hi everyone,

 

I'm learning php and I would like to ask for a little help with a script I'm trying to write. The script has a form where users can post data back to the script via text area and I'm a little confused on changing the data entered into the form into an array. Basically I need to set up the script so the user can put an undetermined number of items inside the text area, one item per line. When submitted to the script, I need to convert the data in the text area into an array. Any help is greatly appreciated!

Link to comment
https://forums.phpfreaks.com/topic/56006-solved-php-textarea-array-help/
Share on other sites

Try this and see how it works:

 

<?php

$items = $_POST['items'];

//create the array
$list = explode("\n", $items);

//display the array contents
foreach ($list as $key){
   echo $key.'<br>';
}
echo '<p>';

?>

<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
   <textarea name="items" rows=10 cols=30></textarea>
   <br>
   <input type="submit" name="go" value="Submit">
</form>

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.