views:

43

answers:

2

Im working on a PHP project that involves selecting a song, hitting the submit button and then having the PHP loading the song player to the correct option. anyway: for the song selection I want to load these options from a txt file with the following formatting:
All For Love
Break Free
Come to the River
For You Name


which I want to be processed to end up like this:
< option value="All For Love"> All For Love< /option>
< option value="Break Free">Break Free< /option>
< option value="Come to the River">Come To The River< /option>
< option value="For Your Name">For Your Name< /option>


how would I go about achieving this? project so far

+1  A: 
$songs = file('path/to/file/with/songs.txt');
$options = '';
foreach ($songs as $song) {
    $options .= '<option value="'.$song.'">'.$song.'</option>';
}
$select = '<select name="songs">'.$options.'</select>';

echo $select;
kgb
thanks, worked perfectly!
H4Z3Y
+1  A: 
<?php
$file_array = file($file_path);
foreach ($file_array as $song)
  echo '<option value="'.$song.'">'.$song.'</option>'.PHP_EOL;
?>
zilverdistel