Jump to content

[SOLVED] PHP, Textarea, Array help


andymike07

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>

Archived

This topic is now archived and is closed to further replies.

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