重新说明 php 的 feof() 是如何工作的
Reclarification of how feof() of php work
我已阅读the comment about feof()
on PHP manual, and another answer on Whosebug。
所以我明白使用 feof()
并不意味着使用 'crystal ball' 神奇地知道流中是否有更多字符或行,如上面第二个 link 所述.相反,它是一个指示输入操作是否失败的测试(在这种情况下,我只关心PHP的fgetc()
的输入操作) .所以读取的最后一个字符仍然可以。 AND THEN,while(!feof($file_you_read_from))
的 feof()
仍将是 false,因为最后一个 fgetc()
仍然成功并且 在 又一个循环,其中 fgetc()
尝试读取并失败,只有到那时 feof()
才会被设置为 true。我对么?我是不是误会了什么?
feof
in PHP 和 C 一样工作。
如果是 false
则检查最后一个操作,否则 returns 缓存值。
Checks whether the end-of-File indicator associated with stream is
set, returning a value different from zero if it is.
This indicator is generally set by a previous operation on the stream
that attempted to read at or past the end-of-file.
Notice that stream's internal position indicator may point to the
end-of-file for the next operation, but still, the end-of-file
indicator may not be set until an operation attempts to read at that
point.
This indicator is cleared by a call to clearerr, rewind, fseek,
fsetpos or freopen. Although if the position indicator is not
repositioned by such a call, the next i/o operation is likely to set
the indicator again.
我已阅读the comment about feof()
on PHP manual,
所以我明白使用 feof()
并不意味着使用 'crystal ball' 神奇地知道流中是否有更多字符或行,如上面第二个 link 所述.相反,它是一个指示输入操作是否失败的测试(在这种情况下,我只关心PHP的fgetc()
的输入操作) .所以读取的最后一个字符仍然可以。 AND THEN,while(!feof($file_you_read_from))
的 feof()
仍将是 false,因为最后一个 fgetc()
仍然成功并且 在 又一个循环,其中 fgetc()
尝试读取并失败,只有到那时 feof()
才会被设置为 true。我对么?我是不是误会了什么?
feof
in PHP 和 C 一样工作。
如果是 false
则检查最后一个操作,否则 returns 缓存值。
Checks whether the end-of-File indicator associated with stream is set, returning a value different from zero if it is.
This indicator is generally set by a previous operation on the stream that attempted to read at or past the end-of-file.
Notice that stream's internal position indicator may point to the end-of-file for the next operation, but still, the end-of-file indicator may not be set until an operation attempts to read at that point.
This indicator is cleared by a call to clearerr, rewind, fseek, fsetpos or freopen. Although if the position indicator is not repositioned by such a call, the next i/o operation is likely to set the indicator again.