Nam G VU
Nam G VU

Reputation: 35434

PHP how to redirect stdin to text file?

As discussed here for PHP, we can redirect stdout to text file. I'm looking for similar way to redirect stdin to file too.

Though, my google search and search on our site results with little helpful. We can easily do that in Python as discussed here

Upvotes: 2

Views: 1129

Answers (1)

Khazul
Khazul

Reputation: 179

Not sure if this is what you want... but you can read stdin like this:

$stdin = fopen('php://stdin', 'r');
$input = trim(fgets($stdin));
fclose($stdin);
file_put_contents('filename',$input);

Upvotes: 1

Related Questions