Home  >  Article  >  Backend Development  >  What does php stdin mean?

What does php stdin mean?

藏色散人
藏色散人Original
2021-12-08 10:37:373187browse

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.

What does php stdin mean?

#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(&#39;php://stdin&#39;, &#39;r&#39;);
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to remove php bomNext article:How to remove php bom