【问题标题】:Reading stdin line by line逐行读取标准输入
【发布时间】:2014-03-09 18:27:23
【问题描述】:

我正在使用 fgets 读取 STDIN,但问题是,即使我将内容复制粘贴到 STDIN,我也需要读取一行。

imput example:
1st line
2nd line
3rd line


code:
while (FALSE !== ($line = fgets(STDIN))) {
echo $line;
}

该脚本会将所有 3 行放入变量 $line,但我只需将“第一行”放入 $line。怎么做?对不起我的英语不好

【问题讨论】:

  • 用\n分隔符分割

标签: php stdin


【解决方案1】:

根据php.net 这应该可以工作

$line=trim(fgets(STDIN));

否则你可以使用这个

$handle=$fopen('file.ext');
$line=fgets($handle);
fclose($handle);

【讨论】:

    猜你喜欢
    • 2014-04-09
    • 2011-06-02
    • 1970-01-01
    • 2011-02-17
    • 1970-01-01
    • 2014-01-07
    相关资源
    最近更新 更多