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!"; ?> 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...) 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); 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) 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 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! Link to comment https://forums.phpfreaks.com/topic/169498-solved-input-arrays/#findComment-894320 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.