将文本文件列表载入< option>标签 [英] load text file list into <option> tags

查看:91
本文介绍了将文本文件列表载入< option>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 PHP 项目,其中包括选择歌曲,点击提交按钮,然后让 PHP 将歌曲播放器加载到正确的选项。

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.

对于歌曲选择,我希望使用以下格式从 txt 文件加载这些选项:

For the song selection I want to load these options from a txt file with 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 /> 






如何实现这个目标?
项目到目前为止

推荐答案

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

这篇关于将文本文件列表载入&lt; option&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆