Home > Backend Development > PHP Problem > What does php stdin mean?

What does php stdin mean?

藏色散人
Release: 2023-03-14 11:02:02
Original
3312 people have browsed it

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);
Copy after login

Running results:

请输入内容:sad
输入的内容为: sad
请输入: asdasdasdasdasdasd
输入为: asdasdasdasd(这里因为设置了最多读取12个字符,设置更多一些就可以完整显示)
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template