Home  >  Article  >  Backend Development  >  Parsing the fopen() function in php and using the open file mode explanation_PHP tutorial

Parsing the fopen() function in php and using the open file mode explanation_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:05:56907browse

fopen() function is used to open files in PHP.
The first parameter of this function contains the name of the file to be opened, and the second parameter specifies which mode to use to open the file:

Copy the code The code is as follows:

$file=fopen("welcome.txt","r");
?>

Files may be opened in the following modes:
r : read-only. The pointer is positioned at the beginning of the file, and no error will be reported if the file is entered.
r+: read/write. The pointer is positioned at the beginning of the file. If the file does not exist, an error will be reported.
w : Write only. Opens and clears the contents of the file, or creates a new file if it does not exist.
w+: read/write. Opens and clears the contents of the file, or creates a new file if it does not exist.
a : Append. Open and position the pointer at the end of the file, or create a new file if it does not exist.
a+ : read/append. Open and position the pointer at the end of the file, or create a new file if it does not exist.
x : Write only. Create new file. Returns FALSE if the file exists.
x+ : read/write. Create new file. If the file already exists, returns FALSE and an error.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327673.htmlTechArticlefopen() function is used to open files in PHP. The first parameter of this function contains the name of the file to be opened, and the second parameter specifies which mode to use to open the file: Copy code...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn