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
Question
How can I read the contents of stdin (up until EOF) into a string in PHP?
Solution
ended up figuring it out myself:
$input_data = file_get_contents("php://stdin");
Solution
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.