简体   繁体   English

输入PHP后显示带回声的输入文本

[英]Display entered text with echo after input PHP

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. 用户在HTML文本框中输入文本然后点击提交,PHP回显是输入的文本。 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. 我想要这样的东西,除了$foo是输入的文本。

<html>
<input type="text" name="something" value="$foo"/>
<html>
<?php
echo $foo = "ben";
echo "foo is $foo"; // foo is foobar


?>

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM