문제

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

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top