Superian Posted August 9, 2009 Share Posted August 9, 2009 This should be simple, but I am having a hard time figuring this thing out! I have a textarea that I am trying to insert multiple values into. <form action="music.php" method="post" > <textarea name="tracks" rows="15" cols="20" id="" tabindex="3" class="" style="width: 300px;"></textarea> <input type="submit" name="submit_tracks" value="Music"> </form> I am having problems placing the results into an array. What am I doing wrong? <?php if($_POST['submit_tracks']) { //This is the array containing the track information $tracklisting = $_POST['tracks']; $tracklisting = array(); //This is the function which will grab anything after the . and return it function trackname($string){ $file = $string; $i = strrpos($file,'.'); $trackname = substr($file,$i+1); return $trackname; } foreach($tracklisting as $track) { $trackoutput = trackname($track); print "<li>".$trackoutput."</li>"; } } else print "No Output!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169498-solved-input-arrays/ Share on other sites More sharing options...
.josh Posted August 9, 2009 Share Posted August 9, 2009 When you say you are trying to insert multiple values into a textarea, what are you using as a delimiter? In order to make the posted info into an array, you need to explode at whatever delimiter you are using in the form (like a comma or \n if pressing enter after each one, etc...) Quote Link to comment https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894301 Share on other sites More sharing options...
wildteen88 Posted August 9, 2009 Share Posted August 9, 2009 This line $tracklisting = array(); Is overwriting this line $tracklisting = $_POST['tracks']; I guess you want to loop through the lines enter in the textarea. In which case you'll want to do This: $tracks_entered = str_replace(array("\r\n", "\r"), "\n", $_POST['tracks']); $tracklisting = explode("\n", $tracks_entered); Quote Link to comment https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894302 Share on other sites More sharing options...
Superian Posted August 9, 2009 Author Share Posted August 9, 2009 When you say you are trying to insert multiple values into a textarea, what are you using as a delimiter? In order to make the posted info into an array, you need to explode at whatever delimiter you are using in the form (like a comma or \n if pressing enter after each one, etc...) After each period 01. Plies - Chef (3:28) 02. Plies Feat. Mario & Hurricane Chris - Headboard (3:33) 03. Plies - On Yac (0:49) Quote Link to comment https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894304 Share on other sites More sharing options...
wildteen88 Posted August 9, 2009 Share Posted August 9, 2009 My suggestion will do what you want. Replace this $tracklisting = $_POST['tracks']; $tracklisting = array(); With the code I suggested Quote Link to comment https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894306 Share on other sites More sharing options...
Superian Posted August 9, 2009 Author Share Posted August 9, 2009 Thanks wildteen88! With your code, I do no have to use the function! Quote Link to comment https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894320 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.