将文本文件列表加载到

发布于 2024-09-24 14:02:06 字数 816 浏览 0 评论 0原文

我正在开发一个 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 /> 

我将如何实现这一目标? 到目前为止的项目

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 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 /> 

How would I go about achieving this?
project so far

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

痴情 2024-10-01 14:02:06
$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;
$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;
假情假意假温柔 2024-10-01 14:02:06
<?php
$file_array = file($file_path);
foreach ($file_array as $song)
  echo '<option value="'.$song.'">'.$song.'</option>'.PHP_EOL;
?>
<?php
$file_array = file($file_path);
foreach ($file_array as $song)
  echo '<option value="'.$song.'">'.$song.'</option>'.PHP_EOL;
?>
烟柳画桥 2024-10-01 14:02:06
$file_path = 'data/canada.txt'; 
$file_array = file($file_path); $options = '';

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


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

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

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


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

 echo $select;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文