Home >Backend Development >PHP Tutorial >PHP implementation code for reading and writing files
2.fclose (close file) grammar: fclose(filepointer) filepointer, the file pointer to be closed. The fclose function returns TRUE if successful and FALSE if failed. Example:
3.feof( Detects whether the end of file has been reached) grammar: feof(filepointer) filepointer, the file pointer to be detected, which must point to a file that was successfully opened but not closed. If the file pointer reaches the end of the file or an error occurs, the feof function returns TRUE. Example:
4.fgets (read a line from the file pointer) grammar: fgets(filepointer) filepointer, the file pointer to be read. Reads a line from the file and returns a string if successful, or FALSE if failed. Example:
Assume the content of test.txt is: hello world hello cnblogs hello heihaozi hello everyone The page output results are: Line 1: hello world Line 2: hello cnblogs Line 3: hello heihaozi Line 4: hello everyone 5.fwrite (write file) grammar: fwrite(filepointer,string) filepointer, the file pointer to be written. string, the string to be written. Returns the number of characters written if successful, or FALSE if failed. Example:
The page output result is: Write a total of 100 characters test.txt file will be written: Line 1: Hello World! Line 2: Hello World! Line 3: Hello World! Line 4: Hello World! Line 5: Hello World! |