Home  >  Article  >  Backend Development  >  php feof function

php feof function

高洛峰
高洛峰Original
2016-11-29 15:04:131262browse

If the file pointer reaches EOF or an error occurs, it returns TRUE, otherwise it returns an error, including socket timeout, and in other cases, returns FALSE.

Syntax: feof(file)

Parameter description

file required, specifies the open to be checked File.

Note: The file parameter is a file pointer. This file pointer must be valid and must point to a file that was successfully opened by fopen() or fsockopen() but has not been closed by fclose().

PHP example code As follows:

// if file can not be read or doesn’t exist fopen function returns false

$file = @fopen("no_such_file", "r");

// false from fopen will issue warning and result in infinite loop here

while (!feof($file)) {

}

fclose($file);

?>

$fh = fopen("/home/www.phpfensi.com/data/users.txt", "rt");

while (!feof($fh)) echo fgets($fh);

fclose($fh) ;

?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:rename() function in phpNext article:rename() function in php