redirect a file contents to standard input in php

2019-02-25 03:10发布

I have a file abc.txt with contents like:

hello
hi
good
bad
...
....

Now, How to redirect the contents of the file line by line to a php script's standard input, so that when the php script is executed, it can collect the inputs by any of these commands:

$f = fopen('php://stdin', 'r');
$line = fgets($f);

or

$f = fgets(STDIN);

标签: php stdin
1条回答
Root(大扎)
2楼-- · 2019-02-25 03:39
php yourscript.php < yourinputfile

should do the trick.

查看更多
登录 后发表回答