Display entered text with echo after input PHP

房东的猫 提交于 2019-12-18 07:12:10

问题


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>
<input type="text" name="something" value="$foo"/>
<html>
<?php
echo $foo = "ben";
echo "foo is $foo"; // foo is foobar


?>

回答1:


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>


来源:https://stackoverflow.com/questions/9046353/display-entered-text-with-echo-after-input-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!