title besides title

 

Monday, November 26, 2012

PHP : Files - [18.5] Reading from Standard Input

18.5.1 Problem

You want to read from standard input.

18.5.2 Solution

Use fopen( ) to open php://stdin:
$fh = fopen('php://stdin','r') or die($php_errormsg);
while($s = fgets($fh,1024)) {
    print "You typed: $s";
}

18.5.3 Discussion

Section 20.4 discusses reading data from the keyboard in a command-line context. Reading data from standard input isn't very useful in a web context, because information doesn't arrive via standard input. The bodies of HTTP POST and file-upload requests are parsed by PHP and put into special variables. They can't be read on standard input, as they can in some web server and CGI implementations.