H4Z3Y H4Z3Y - 1 year ago 48
HTML Question

load text file list into <option> tags

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

Answer Source
$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;