Home > Article > Backend Development > What does php stdin mean?
stdin in php is a constant, its function is to read content from the console. When encountering this constant or opening the "php://stdin" script through the fopen() function, it will wait for user input. , until the user presses the Enter key to submit.
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
What does stdin mean?
PHP STDIN usage:
"STDIN" in PHP language is used for slave control The platform reads content. When encountering this constant or opening php://stdin through the fopen() function, the script will wait for the user to input content until the user presses the Enter key to submit.
Write a stdin.php and test it:
<?php echo "请输入内容:"; $jimmy = fgets(STDIN); echo sprintf("输入的内容为: %s\n", $jimmy); $demo = fopen('php://stdin', 'r'); echo "请输入: "; $test = fread($demo, 12); //最多读取12个字符 echo sprintf("输入为: %s\n", $test); fclose($demo);
Running results:
请输入内容:sad 输入的内容为: sad 请输入: asdasdasdasdasdasd 输入为: asdasdasdasd(这里因为设置了最多读取12个字符,设置更多一些就可以完整显示)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does php stdin mean?. For more information, please follow other related articles on the PHP Chinese website!