开发者

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.

For the song selection I want to load these options from a txt file w开发者_运维知识库ith the following formatting:

<br />
<code>All For Love <br /> Break Free <br />Come to the River <br />For You Nam    </code>

Which I want to be processed to end up like this:

<br /> <code>
< option value="All For Love"> All For Love< /option> <br /> 
< option value="Break Free">Break Free< /option> <br /> 
< option value="Come to the River">Come To The River< /option> <br /> 
< option value="For Your Name">For Your Name< /option> <br /> 

How would I go about achieving this? project so far


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


<?php
$file_array = file($file_path);
foreach ($file_array as $song)
  echo '<option value="'.$song.'">'.$song.'</option>'.PHP_EOL;
?>


$file_path = 'data/canada.txt'; 
$file_array = file($file_path); $options = '';

foreach ($file_array as $song){   
   $options .= ''.$song.''; 
}


 $select = ''.$options.'';

 echo $select;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜