我搜索了 Stackoverflow 并发现了一些类似的问题,但无法理解答案。我 2 天前才学 PHP,所以请放轻松。
我的问题是我正在使用一个表单让用户编写一些文本并将其提交到文件中。当他们点击提交时,文本被写入文件,下次他们访问表单时,文本仍保留在表单中供他们修改。问题是,如果输入并提交了任何形式的引用,那么前面会添加一个\。
示例:用户写:“hello”用户点击提交表单重新加载,“hello”输出为“hello”
我知道 \ 取消了诸如引号之类的内容,因此可以将其作为字符串输出,但是是否可以使用 $_POST 来存储表单数据并且在我使用引号时没有 \ ?
请详细说明,因为我只是 PHP 的新手。提前致谢。这是导致我的问题的代码:
echo '<div class="wrap">';
// makes an if statement to check if the submit button has been pushed
if ( isset( $_POST['Submit1'] ) ) {
// opens the include file and writes the contents of "left-form" to the file. left-form is the name of the html text area
$file = fopen($_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/mytheme/options/index_left.php', "w");
fwrite($file,$_POST["left_form"]);
fclose($file);
}
echo '<p><form method="POST" action=""><textarea rows="4" cols="50" name="left_form">';
// includes the contents of the file being written to as the text inside the text field
include $_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/mytheme/options/index_left.php';
echo '</textarea></p>';
echo '<input type="submit" value="Submit" name="Submit1"></form>';
// sets an if statement to check if the post button has been hit to display a message that it has been posted
if ( isset( $_POST['Submit1'] ) ) {
echo htmlspecialchars($_POST["left_form"]) . '</br>HAS BEEN POSTED';
}
echo '</div>';
}