我正在开发一个 PHP 项目,包括选择一首歌曲,点击提交按钮,然后让 PHP 将歌曲播放器加载到正确的选项中。
对于歌曲选择,我想使用以下格式从 txt 文件加载这些选项:
<br />
<code>All For Love <br /> Break Free <br />Come to the River <br />For You Nam </code>
我想要处理的最终结果如下:
<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 />
我将如何实现这一目标? project so far
答案 0 :(得分:3)
$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;
答案 1 :(得分:1)
<?php
$file_array = file($file_path);
foreach ($file_array as $song)
echo '<option value="'.$song.'">'.$song.'</option>'.PHP_EOL;
?>
答案 2 :(得分:-1)
$file_path = 'data/canada.txt';
$file_array = file($file_path); $options = '';
foreach ($file_array as $song){
$options .= ''.$song.'';
}
$select = ''.$options.'';
echo $select;