PHP feof() ฟังก์ชัน
คำนิยามและวิธีใช้
feof() ฟังก์ชันตรวจสอบว่าได้ถึงท้ายแฟ้มหรือไม่ (eof)
Returns TRUE if the file pointer reaches EOF or an error occurs, otherwise returns an error (including socket timeout), and returns FALSE otherwise.
Syntax
feof(file)
Parameters | Description |
---|---|
file | Required. Specifies the open file to be checked. |
Description
file the parameter is a file pointer. This file pointer must be valid and must point to a file fopen() or fsockopen() is successful in opening (but has not been fclose() the file that is closed ()
Tips and comments
Tip:feof() function is very useful for traversing data of unknown length.
Note:If the server does not close the connection opened by fsockopen(), feof() will keep waiting until the timeout and return TRUE. The default timeout limit is 60 seconds, and you can change this value using stream_set_timeout().
Note:If the passed file pointer is invalid, it may fall into an infinite loop because EOF does not return TRUE.
Example
<?php $file = fopen("test.txt", "r"); //Output all lines in the text until the end of the file. while(! feof($file)) { echo fgets($file). "<br />"; } fclose($file); ?>
Output:
Hello, this is a test file. There are three lines here. This is the last line.