Reading line by line from STDIN

php, pipe, stdin

Solution

use `STDIN` constant as file handler.

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

Note: fgets on STDIN reads the `\n` character.

Problem

I want to do something like this: ``` $ [mysql query that produces many lines] | php parse_STDIN.php ``` In `parse_STDIN.php` file I want to be able to parse my data line by line from stdin.

Original source