Home > Article > Backend Development > How to use php standard input
How to use php standard input
php standard input and output allows us to interact in the command line, together Let’s see how to use it.
<?php // ask for input fwrite(STDOUT, "Enter your name: "); // get input $name = trim(fgets(STDIN)); // 接收用户输入 // write input back fwrite(STDOUT, "Hello, $name!"); ?>
Running method:
1. Run cmd
2. Jump to the directory where php.exe is located
3. Type the command
to run:
php inouttest.php
The running result is:
Enter your name: davy Hello, davy!
Among them:
Constant Description
STDIN Standard Input device
STDOUT Standard output device
STDERR Standard error device
You can use these three constants in PHP scripts to accept user input or display processing and calculated results.
PHP processing process is as follows: The fwrite() function will first write a message to the standard output device and ask for the user's name. It then reads the user input information obtained from the standard input device into a PHP variable and combines it into a string. Then use fwrite() to print the string to the standard output device
For more PHP-related knowledge, please visit PHP Chinese website!
The above is the detailed content of How to use php standard input. For more information, please follow other related articles on the PHP Chinese website!