Question

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

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top