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.
The built-in function in c programming is getline() which is used for reading the lines from the stdin. But we can also use other functions like getchar() and scanf() for reading the lines.
Use fileinput. input() reads through all the lines in the input file names specified in command-line arguments. If no argument is specified, it will read the standard input provided.
use STDIN
constant as file handler.
while($f = fgets(STDIN)){ echo "line: $f"; }
Note: fgets on STDIN reads the \n
character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With