PHP Standard Input
PHP is primarily known for web development where standard input is unavailable. However, PHP's versatility extends to general-purpose scripting when adhering to its web-based conventions. This article explores the possibility of PHP scripts retrieving input from stdin using fgetc() or other input functions.
To input data from stdin using PHP, a file handle to php://stdin can be created. Subsequently, data can be read using fgets() (for line input) or fgetc() (for single character input).
Here's an example PHP script:
<code class="php"><?php $f = fopen('php://stdin', 'r'); while ($line = fgets($f)) { echo $line; } fclose($f); ?></code>
By executing this script, the PHP program reads and displays input provided through the standard input channel.
The above is the detailed content of How Can I Use PHP Standard Input for Scripting?. For more information, please follow other related articles on the PHP Chinese website!