将文件内容重定向到 php 中的标准输入 [英] redirect a file contents to standard input in php

查看:40
本文介绍了将文件内容重定向到 php 中的标准输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件 abc.txt,其内容如下:

I have a file abc.txt with contents like:

hello
hi
good
bad
...
....

现在,如何将文件的内容逐行重定向到 php 脚本的标准输入,以便在执行 php 脚本时,它可以通过以下任一命令收集输入:

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);

$f = fgets(STDIN);

推荐答案

php yourscript.php < yourinputfile

应该可以解决问题.

这篇关于将文件内容重定向到 php 中的标准输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆