Jump to content

[SOLVED] Input & Arrays


Superian

Recommended Posts

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

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

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

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

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.