当 here 文档位于 php 的变量中时,如何调用 here 文档中的输入标签?
这是我的代码:
<?php
$myForm = <<<FORMSTUFF
<h3>Generate ASCII Table</h3>
<form action="$_SERVER[PHP_SELF]" method="post">
<label for="numRows">Number of rows:</label>
<input type="text" name="numRows" id="numRows" value="32">
<br><br>
<input type="submit" name="go" value="Create ASCII Table">
</form>
FORMSTUFF;
$numRows = $_POST['numRows'];
?>
我试过使用“get”而不是“post”,但没有用。我还尝试将“$_POST”替换为“$myForm”,但也没有用。
your text
在 heredoc 中使用数组字符串索引的方式略有变化。此外,您还缺少用于有条件地处理处理的 POST 方法检查
<?php
$myForm = <<<FORMSTUFF
<h3>Generate ASCII Table</h3>
<form action="{$_SERVER['PHP_SELF']}" method="post">
<label for="numRows">Number of rows:</label>
<input type="text" name="numRows" id="numRows" value="32">
<br><br>
<input type="submit" name="go" value="Create ASCII Table">
</form>
FORMSTUFF;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$numRows = $_POST['numRows'];
// your code comes here;
return;
}
?>