Php 将单元格表中的多行转换为选择选项
我的项目是如何显示表格的单元格,而不是文本,而是选择选项 我有简单的代码:Php 将单元格表中的多行转换为选择选项,php,html,Php,Html,我的项目是如何显示表格的单元格,而不是文本,而是选择选项 我有简单的代码: <form method="post"> <textarea name="input"></textarea> <button type="submit" name="button">button</button> <table class="table table-bordered" id="tableAll"> <thead> <
<form method="post">
<textarea name="input"></textarea>
<button type="submit" name="button">button</button>
<table class="table table-bordered" id="tableAll">
<thead>
<tr>
<th class="col-md-1">name</th>
</tr>
</thead>
<tbody>
<tr>
<?php
if(isset($_POST['button']))
{
echo "<td>".$_POST["input"]."</td>";
}
?>
</tr>
</tbody>
</table>
</form>
<style>
td { white-space:pre }
</style>
因此,从输入中,我希望转换表格的单元格,以选择页面中的选项,如下所示:
Andy
Alex
John
etc...
<table class="table table-bordered" id="tableAll">
<thead>
<tr>
<th class="col-md-1">name</th>
</tr>
</thead>
<tbody>
<tr>
<select>
<option>Andy</option>
<option>Alex</option>
<option>John</option>
<option>etc...</option>
</select>
</tr>
</tbody>
</table>
名称
安迪
亚历克斯
约翰
等
您可以按如下方式执行:-
<?php
if(isset($_POST["input"]))
{
$select_data = explode("\n",$_POST["input"]); // explode input data with new line
}
?>
<?php if(count($select_data) >0){?>
<select>
<?php
foreach($select_data as $select_dat){?>
<option value = "<?php echo $select_dat;?>"><?php echo $select_dat;?></option>
<?php }?>
</select>
<?php }?>