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

高洛峰
Release: 2023-03-03 20:30:02
Original
1564 people have browsed it

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");
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!