公告
财富商城
积分规则
提问
发文
2019-03-20 07:27发布
做自己的国王
How can I make a PHP input thing like prompt('example prompt') in javascript?
prompt('example prompt')
Not like a form, like a prompt().
prompt()
<?php echo "What do you want to input? "; $input = rtrim(fgets(STDIN)); echo "I got it:\n" . $input;
Sample output:
# php test.php What do you want to input? Hello, I'm here! I got it: Hello, I'm here!
<?php $input = $argv[1]; echo "I got it:\n" . $input;
# php test.php "Hello, I'm here!" I got it: Hello, I'm here!
You can't take input in the middle of php execution since it finishes before the page is actually shown to the user. However, you can get input using HTML and receive that using php. Here's a really basic example:
<?php echo $_POST['value']; ?> <form method="post" action=""> <input type="text" name="value"> <input type="submit"> </form>
It takes the user input and reloads the page. Then, it echoes what the input was.
最多设置5个标签!
Solution #1: Prompt for get input inside of anywhere code:
Sample output:
Solution #2: If you want get input in firstly inline when run php:
Sample output:
You can't take input in the middle of php execution since it finishes before the page is actually shown to the user. However, you can get input using HTML and receive that using php. Here's a really basic example:
It takes the user input and reloads the page. Then, it echoes what the input was.