Reputation: 69
I am reading STDIN with fgets but problem is, that I need to read one single line even if I copy-paste content to STDIN.
imput example:
1st line
2nd line
3rd line
code:
while (FALSE !== ($line = fgets(STDIN))) {
echo $line;
}
This script will put all there 3 lines in to variable $line, but I need to put only "1st line" to $line. How to do it? sorry for my bad english
Upvotes: 2
Views: 290
Reputation: 3490
According to php.net this should work
$line=trim(fgets(STDIN));
Otherwise you could use this
$handle=$fopen('file.ext');
$line=fgets($handle);
fclose($handle);
Upvotes: 3