andymike07 Posted June 18, 2007 Share Posted June 18, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/56006-solved-php-textarea-array-help/ Share on other sites More sharing options...
pocobueno1388 Posted June 18, 2007 Share Posted June 18, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/56006-solved-php-textarea-array-help/#findComment-276605 Share on other sites More sharing options...
andymike07 Posted June 18, 2007 Author Share Posted June 18, 2007 That's exactly what I needed. Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/56006-solved-php-textarea-array-help/#findComment-276634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.