Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

html - 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. 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


?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...