PHP Files Reading from Standard Input - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Files Reading from Standard Input - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Tuesday, July 9, 2019

PHP Files Reading from Standard Input

PHP Files


Reading from Standard Input

Problem

You want to read from standard input in a command-line context—for example, to get user input from the keyboard or data piped to your PHP program.

Solution

Use fopen() to open php://stdin:

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

Discussion

Discusses reading data from the keyboard in a command-line context in more detail. 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. Non–file-upload POST request bodies can also be read with the php://input stream.

No comments:

Post a Comment

Post Top Ad