Home > Backend Development > PHP Tutorial > PHP method to open a file in read-only mode, _PHP tutorial

PHP method to open a file in read-only mode, _PHP tutorial

WBOY
Release: 2016-07-13 10:03:36
Original
743 people have browsed it

How to open a file in read-only mode in php,

The example in this article describes how to open a file in read-only mode in php. Share it with everyone for your reference. The specific analysis is as follows:

In PHP, you can open a file through fopen(). The second parameter is set to "r" to indicate that it has been opened in read-only mode. The function returns a file handle, and other functions can use this file handle to process the file in different ways. Read

<&#63;php 
$file = fopen("/tmp/file.txt", "r");
print("Type of file handle: " . gettype($file) . "\n");
print("The first line from the file handle: " . fgets($file));
fclose($file); 
&#63;>
Copy after login

The above code returns the following results

Type of file handle: resource
The first line from the file handle: Welcome to sharejs.com php tutorials

After the file reading is completed, you need to use the fclose() function to close the file handle to release resources

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968255.htmlTechArticleHow to open files in read-only mode in php. This article describes how to open files in read-only mode in php. method. Share it with everyone for your reference. The specific analysis is as follows: In php, you can...
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