Home >Backend Development >PHP Tutorial >Analyze the fopen() function in php and use the open file mode description

Analyze the fopen() function in php and use the open file mode description

高洛峰
高洛峰Original
2016-12-21 15:56:421641browse

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:

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

The file 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.

For more related articles on analyzing the fopen() function in PHP and explaining how to open the file mode, please pay attention to the PHP Chinese website!

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