Question

How can I read the contents of stdin (up until EOF) into a string in PHP?

How can I read the contents of stdin (up until EOF) into a string in PHP?

 45  21615  45
1 Jan 1970

Solution

 74

ended up figuring it out myself:

$input_data = file_get_contents("php://stdin");
2009-05-05

Solution

 15

Here's an alternative: You can use stream_get_contents to get everything from an open stream (AKA a file handle). STDIN is an already open handle equivalent to what you get if you call fopen('php://stdin') (see reference: Input/output streams)

So: you can use

$input_data = stream_get_contents(STDIN);

which is equivalent to the accepted answer.

2017-05-24