从STDIN逐行读取 [英] Reading line by line from STDIN

查看:84
本文介绍了从STDIN逐行读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情:

$ [mysql query that produces many lines] | php parse_STDIN.php

parse_STDIN.php文件中,我希望能够从stdin逐行解析我的数据.

In parse_STDIN.php file I want to be able to parse my data line by line from stdin.

推荐答案

使用STDIN常量作为文件处理程序.

use STDIN constant as file handler.

while($f = fgets(STDIN)){
    echo "line: $f";
}

注意:STDIN上的fgets读取\n字符.

Note: fgets on STDIN reads the \n character.

这篇关于从STDIN逐行读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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