输入 PHP 后回显显示输入的文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9046353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display entered text with echo after input PHP
提问by Ben Thomson
I want to do something very simple. After a user enters text in an HTML text box then hits submit, the PHP echo's the entered text. I searched all over and I cant find out how to do it! There must be some way! I want something like this except $foo
is what the entered text was.
我想做一些非常简单的事情。用户在 HTML 文本框中输入文本然后点击提交后,PHP 回显输入的文本。我到处搜索,我无法找到怎么做!一定有办法!我想要这样的东西,除了$foo
输入的文本是什么。
<html>
<input type="text" name="something" value="$foo"/>
<html>
<?php
echo $foo = "ben";
echo "foo is $foo"; // foo is foobar
?>
回答by knittl
FTFY
FTFY
<html>
<head><title>some title</title></head>
<body>
<form method="post" action="">
<input type="text" name="something" value="<?= isset($_POST['something']) ? htmlspecialchars($_POST['something']) : '' ?>" />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])) {
echo 'You entered: ', htmlspecialchars($_POST['something']);
}
?>
</body>
<html>