PHP读取文件并创建下拉菜单 [英] php read file and create drop down menu
本文介绍了PHP读取文件并创建下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下php代码,它们创建下拉菜单来读取包含名称的文本文件
I have following php code which create Drop-Down menu reading text file which contain name
files.txt
files.txt
JAMES
MARK
TONY
drop-down.php
drop-down.php
<?php
$path = "files.txt";
$file = fopen($path, 'r');
$data = fread($file, filesize($path));
fclose($file);
$lines = explode(PHP_EOL,$data);
echo '<select name="file">';
foreach($lines as $line) {
echo '<option value="'. urlencode($line).'">'.$line.'</option>';
}
echo '</select>';
?>
这是代码的POST部分,它是一个循环
Here is the POST section of code, it is a loop
foreach ($_POST["bname"] AS $id => $value)
{
...
...
USERNAME: "'.$_POST["file"][$id].'"
一切正常,但是当我以其他形式提交数据时,我只会得到用户的第一个字母,就像我选择 JAMES
并提交数据时,我只会得到<$ c 。$ _ POST
中的$ c> J 字母。我想要全名 JAMES
,我的代码有什么问题?
Everything working but when i submit data to other form i am getting only first letter of users like if i select JAMES
and submit data i am only getting J
letter in .$_POST
. I want Full name JAMES
, what is wrong in my code?
推荐答案
您选择的名称属性错误,必须为:
The name attribute of your select is wrong, must be:
echo '<select name="file[]">';
或
echo '<select name="file[someNumber]">';
这篇关于PHP读取文件并创建下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文