Home > Backend Development > PHP Problem > How to use php standard input

How to use php standard input

angryTom
Release: 2023-02-28 06:06:01
Original
2833 people have browsed it

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

Running method:

1. Run cmd

2. Jump to the directory where php.exe is located

3. Type the command

to run:

php inouttest.php
Copy after login

The running result is:

Enter your name: davy
Hello, davy!
Copy after login

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!

Related labels:
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