Malloc
Malloc

Reputation: 16296

working with the php://stdin I/O streams

I know the way to open and read the content of the file with the fopen function like this:

@fopen("inputfile.txt", "r");

But with the php://stdin i got bit confused

$in = fopen('php://stdin', 'r');

Where should i specify the name of txt file that i attempt to read?

Upvotes: 0

Views: 1183

Answers (1)

mario
mario

Reputation: 145512

php://stdin is for CLI usage. You do not specify a filename directly in PHP then. It is typically utilized from the terminal like this:

echo "input text" | php script.php

or

cat textinput.txt | php do-something.php

Where the thing you pipe into the interpreter is what you receive when reading from stdin.

Btw, you can also just use the STDIN constant, without manually calling fopen first.

Upvotes: 4

Related Questions