feof() 関数は、ファイル終端 (EOF) に達したかどうかをチェックします。
この関数は、エラーが発生した場合、またはEOFに達した場合にTRUEを返します。それ以外の場合はFALSEを返します。
feof(file)
パラメータ | 説明 |
---|---|
file | 必須。チェックするオープンファイルを指定する |
チップ: feof() 関数は、長さが分からないデータをループするときに便利です。
<?php
$file = fopen("test.txt", "r");
//Output a line of the file until the end is reached
$line = fgets($file);
while(! feof($file))
{
echo $line. "<br />";
$line = fgets($file);
}
fclose($file);
?>
上のコードの出力は、次の通り:
Hello, this is a test file.
There are three lines here.
This is the last line.