PHP advanced tutorial (3): PHP file processing

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.