From Scriptwiki
Jump to: navigation, search

Indicates the end of file was reached.


Return the results of the last file access attempt in any script. Simlar to $fopen(<name>).eof will return $true or $false for a specific file handler.


Let's imagine we have the following example file moo.txt in our mircdir:


If we want to search moo.txt read in the 3rd line and echo the line and check if we're at the end of the line, it can be done like this:

; at first we have to open the file.
fopen moo moo.txt
; let's jump to the third line.
fseek -l moo 3
; and now read this line so that the pointer is set to the end of the line.
echo -a $fread(moo)
; finally, we want to echo $feof and see, what it returns.
echo -a $feof
; this will return 1 as we are at the end of our file.
; never forget to close the file handler.
fclose moo

Below is an example of how to loop though the file one line at a time.

; open the file handler.
fopen moo moo.txt
; as long as $feof returns 0, this while loop will read the next line
while (!$feof) {
 ; echo the line where the pointer is. The pointer will automatically moved to the next line .
 echo -a $fread(moo)
 ; that's why we do not need to increase a variable, as you normally would have to do.
; close the file.
fclose moo