PHP Lecture No 6
PHP Lecture No 6
After a call to the fgets() function, the file pointer has moved to the next line.
PHP Check End-Of-File - feof()
The feof() function checks if the "end-of-file" (EOF) has been reached.
The feof() function is useful for looping through data of unknown length.
E.g
<?php
$myfile = fopen(“abc.txt", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
echo fgets($myfile) . "<br>";
}
fclose($myfile);
?>
PHP Read Single Character - fgetc()
The fgetc() function is used to read a single character from a file.
Syntax
fgetc($myfile);
After a call to the fgetc() function, the file pointer moves to the next character.
If you want to read complete file using fgetc function then use feof function.
PHP Write to File - fwrite()
The fwrite() function is used to write to a file.
Syntax
fwrite($myfile, $txt);
The first parameter of fwrite() contains the name of the file to write to and the second
parameter is the string to be written.