使文本输入向 PHP 发送多个变量

时间:2021-07-10 19:05:20

标签: php input

我的任务是让文本输入发送最多 16 个变量以垂直打印在下方,名称本身彼此水平组织。我正在使用表格来执行此操作(将每个字母打印在一行上),并将这些表格放在更大表格的一行中的单元格中,以便它们水平排列。

这段代码成功打印了一个输入,但它只处理了一个输入。我将它设置为打印更多,我只需要更多输入。我应该只使用一个输入来完成所有这些。我不知道该怎么做。

<html>
    <head>
    <link rel="stylesheet" href="style.css">
    </head>
    <body><br><br>
        <form action="question_2.php" method="post">
            <input type="text" name="$N">
            <button type="submit">Print</button>
        </form>
        <!-- a table for containing tables that are generated within cells in a single row -->
        <table name="teams_table"><tr>
            <?PHP
            // insert it into each input and then to be grabbed via a GET request
              $N = $_GET['$N'];

              // start without any filled "team" cells
              if ($N == null) {
                  return 0;
              } else {
                  // verticalize each team name into a table and insert it into a table cell
                  $name = verticalise($N);
                  echo "<td><table name=team_table>" . $N  . "</table></td>";
                    }
          // turn each string into a table of rows of chars
          function verticalise($N) {
            $char = "";
            for ($a = 0; $a < strlen($N); ++$a) {
               $char .= "<tr><td>" . $N[$a] . "</td></tr>";
            }
            return $char;
          }
          ?>
        </tr></table>
    </body>
</html>

示例输入/输出如下所示: ui

非常感谢帮助

1 个答案:

答案 0 :(得分:0)

您可以尝试让用户用逗号分隔他们的信息,然后像这样使用内置于explode函数的PHP

$newArray = explode(",", $N) 循环并回显每个值或使用换行语句。

相关问题