PHP advanced tutorial (3): PHP file processing fopen () function is used to open a file in PHP.
Open a file
The fopen () function is used to open a file in PHP.
The first parameter of this function contains the name of the file to be opened, and the second parameter specifies the mode used to open the file:
$ File = fopen ("welcome.txt", "r ");
?>
The file may be opened in the following mode:
Example
If fopen () cannot open the specified file, the following example generates a message:
The fclose () function is used to close open files.
Check whether the End-of-filefeof () function has reached the End of the file (EOF ). The feof () function is useful when data with unknown length is traversed cyclically. Note: in w, a, and x modes, you cannot read open files! If (feof ($ file) echo "End of file"; the fgets () function reads files row-by-row from files. Note: after the function is called, the file pointer is moved to the next row.
Example
The following example reads the file row by row until the end of the file:
";}Fclose ($ file) ;?> The character-by-character fgetc () function is used to read files from files character by character. Note: after the function is called, the file pointer is moved to the next character.
Example
The following example reads the file one by one until the end of the file:
PHP Filesystem reference manual if you need a complete PHP file System Reference Manual PHP Filesystem introduction Filesystem functions allow you to access and operate the file system. Installing the Filesystem function is a core component of PHP. These functions can be used without installation. The Runtime configuration file system function behavior is affected by the settings in php. ini. File system configuration options:
The above is the PHP advanced tutorial (3): PHP file processing content, for more information, please follow the PHP Chinese network (www.php1.cn )!